[DEV] better keyboard input
This commit is contained in:
parent
9d07ec9eb6
commit
bec114d53d
@ -14,21 +14,21 @@
|
|||||||
@interface OpenGLView : NSOpenGLView<NSWindowDelegate> {
|
@interface OpenGLView : NSOpenGLView<NSWindowDelegate> {
|
||||||
NSTimer* _refreshTimer;
|
NSTimer* _refreshTimer;
|
||||||
}
|
}
|
||||||
- ()prepareOpenGL;
|
- (void)prepareOpenGL;
|
||||||
- ()drawRect:(NSRect) bounds;
|
- (void)drawRect:(NSRect) bounds;
|
||||||
- ()mouseDown:(NSEvent *) event;
|
- (void)mouseDown:(NSEvent *) event;
|
||||||
- ()mouseDragged:(NSEvent *) event;
|
- (void)mouseDragged:(NSEvent *) event;
|
||||||
- ()mouseUp:(NSEvent *)event;
|
- (void)mouseUp:(NSEvent *)event;
|
||||||
- ()mouseMoved:(NSEvent *)event;
|
- (void)mouseMoved:(NSEvent *)event;
|
||||||
- ()mouseEntered:(NSEvent *)event;
|
- (void)mouseEntered:(NSEvent *)event;
|
||||||
- ()mouseExited:(NSEvent *)event;
|
- (void)mouseExited:(NSEvent *)event;
|
||||||
- ()rightMouseDown:(NSEvent *)event;
|
- (void)rightMouseDown:(NSEvent *)event;
|
||||||
- ()rightMouseDragged:(NSEvent *)event;
|
- (void)rightMouseDragged:(NSEvent *)event;
|
||||||
- ()rightMouseUp:(NSEvent *)event;
|
- (void)rightMouseUp:(NSEvent *)event;
|
||||||
- ()otherMouseDown:(NSEvent *)event;
|
- (void)otherMouseDown:(NSEvent *)event;
|
||||||
- ()otherMouseDragged:(NSEvent *)event;
|
- (void)otherMouseDragged:(NSEvent *)event;
|
||||||
- ()otherMouseUp:(NSEvent *)event;
|
- (void)otherMouseUp:(NSEvent *)event;
|
||||||
//- ()sendEvent:(NSEvent *)event
|
//- (void)sendEvent:(NSEvent *)event
|
||||||
- ()keyDown:(NSEvent *)theEvent;
|
- (void)keyDown:(NSEvent *)theEvent;
|
||||||
- ()flagsChanged:(NSEvent *)theEvent;
|
- (void)flagsChanged:(NSEvent *)theEvent;
|
||||||
@end
|
@end
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
@implementation OpenGLView
|
@implementation OpenGLView
|
||||||
|
|
||||||
static ewol::key::Special guiKeyBoardMode;
|
|
||||||
|
|
||||||
- (void) prepareOpenGL
|
- (void) prepareOpenGL
|
||||||
{
|
{
|
||||||
@ -210,139 +209,6 @@ static ewol::key::Special guiKeyBoardMode;
|
|||||||
MacOs::setMouseState(idEvent, false, point.x, point.y);
|
MacOs::setMouseState(idEvent, false, point.x, point.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
// https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/Reference/Reference.html
|
|
||||||
// http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html
|
|
||||||
-(void)sendEvent:(NSEvent *)event {
|
|
||||||
NSPoint point = [event locationInWindow];
|
|
||||||
EWOL_INFO("sendEvent : " << (float)point.x << " " << (float)point.y);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
// this generate all the event entry availlable ==> like a big keep focus ...
|
|
||||||
- (BOOL)acceptsFirstResponder {
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
- (BOOL)becomeFirstResponder {
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
- (void)keyDown:(NSEvent *)theEvent {
|
|
||||||
bool thisIsAReapeateKey = false;
|
|
||||||
if ([theEvent isARepeat]) {
|
|
||||||
thisIsAReapeateKey = true;
|
|
||||||
}
|
|
||||||
NSString *str = [theEvent charactersIgnoringModifiers];
|
|
||||||
// TODO : set if for every char in the string !!!
|
|
||||||
unichar c = [str characterAtIndex:0];
|
|
||||||
//EWOL_DEBUG("KeyDown " << (char)c);
|
|
||||||
MacOs::setKeyboard(guiKeyBoardMode, (char)c, true, thisIsAReapeateKey);
|
|
||||||
if (true==thisIsAReapeateKey) {
|
|
||||||
MacOs::setKeyboard(guiKeyBoardMode, (char)c, false, thisIsAReapeateKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)keyUp:(NSEvent *)theEvent {
|
|
||||||
bool thisIsAReapeateKey = false;
|
|
||||||
if ([theEvent isARepeat]) {
|
|
||||||
thisIsAReapeateKey = true;
|
|
||||||
}
|
|
||||||
//EWOL_DEBUG("KeyUp ");
|
|
||||||
NSString *str = [theEvent charactersIgnoringModifiers];
|
|
||||||
unichar c = [str characterAtIndex:0];
|
|
||||||
MacOs::setKeyboard(guiKeyBoardMode, (char)c, false, thisIsAReapeateKey);
|
|
||||||
if (true==thisIsAReapeateKey) {
|
|
||||||
MacOs::setKeyboard(guiKeyBoardMode, (char)c, true, thisIsAReapeateKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)flagsChanged:(NSEvent *)theEvent {
|
|
||||||
if (([theEvent modifierFlags] & NSAlphaShiftKeyMask) != 0) {
|
|
||||||
EWOL_DEBUG("NSAlphaShiftKeyMask");
|
|
||||||
if (guiKeyBoardMode.getCapsLock() == false) {
|
|
||||||
guiKeyBoardMode.setCapsLock(true);
|
|
||||||
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardCapLock, true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (guiKeyBoardMode.getCapsLock() == true) {
|
|
||||||
guiKeyBoardMode.setCapsLock(false);
|
|
||||||
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardCapLock, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (([theEvent modifierFlags] & NSShiftKeyMask) != 0) {
|
|
||||||
EWOL_DEBUG("NSShiftKeyMask");
|
|
||||||
if (guiKeyBoardMode.getShift() == false) {
|
|
||||||
guiKeyBoardMode.setShift(true);
|
|
||||||
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardShiftLeft, true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (guiKeyBoardMode.getShift() == true) {
|
|
||||||
guiKeyBoardMode.setShift(false);
|
|
||||||
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardShiftLeft, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (([theEvent modifierFlags] & NSControlKeyMask) != 0) {
|
|
||||||
EWOL_DEBUG("NSControlKeyMask");
|
|
||||||
if (guiKeyBoardMode.getCtrl() == false) {
|
|
||||||
guiKeyBoardMode.setCtrl(true);
|
|
||||||
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardCtrlLeft, true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (guiKeyBoardMode.getCtrl() == true) {
|
|
||||||
guiKeyBoardMode.setCtrl(false);
|
|
||||||
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardCtrlLeft, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (([theEvent modifierFlags] & NSAlternateKeyMask) != 0) {
|
|
||||||
EWOL_DEBUG("NSAlternateKeyMask");
|
|
||||||
if (guiKeyBoardMode.getAlt() == false) {
|
|
||||||
guiKeyBoardMode.setAlt(true);
|
|
||||||
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardAlt, true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (guiKeyBoardMode.getAlt() == true) {
|
|
||||||
guiKeyBoardMode.setAlt(false);
|
|
||||||
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardAlt, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (([theEvent modifierFlags] & NSCommandKeyMask) != 0) {
|
|
||||||
EWOL_DEBUG("NSCommandKeyMask");
|
|
||||||
if (guiKeyBoardMode.getMeta() == false) {
|
|
||||||
guiKeyBoardMode.setMeta(true);
|
|
||||||
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardMetaLeft, true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (guiKeyBoardMode.getMeta() == true) {
|
|
||||||
guiKeyBoardMode.setMeta(false);
|
|
||||||
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardMetaLeft, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (([theEvent modifierFlags] & NSNumericPadKeyMask) != 0) {
|
|
||||||
EWOL_DEBUG("NSNumericPadKeyMask");
|
|
||||||
if (guiKeyBoardMode.getNumLock() == false) {
|
|
||||||
guiKeyBoardMode.setNumLock(true);
|
|
||||||
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardNumLock, true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (guiKeyBoardMode.getNumLock() == true) {
|
|
||||||
guiKeyBoardMode.setNumLock(false);
|
|
||||||
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardNumLock, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (([theEvent modifierFlags] & NSHelpKeyMask) != 0) {
|
|
||||||
EWOL_DEBUG("NSHelpKeyMask");
|
|
||||||
}
|
|
||||||
if (([theEvent modifierFlags] & NSFunctionKeyMask) != 0) {
|
|
||||||
EWOL_DEBUG("NSFunctionKeyMask");
|
|
||||||
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardContextMenu, true);
|
|
||||||
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardContextMenu, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define FRAME_INTERVAL (0.01)
|
#define FRAME_INTERVAL (0.01)
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#import <ewol/context/MacOs/Windows.h>
|
#import <ewol/context/MacOs/Windows.h>
|
||||||
#import <ewol/context/MacOs/OpenglView.h>
|
#import <ewol/context/MacOs/OpenglView.h>
|
||||||
#include <ewol/context/MacOS/Context.h>
|
#include <ewol/context/MacOS/Context.h>
|
||||||
|
#include <ewol/key/key.h>
|
||||||
|
|
||||||
#include <ewol/debug.h>
|
#include <ewol/debug.h>
|
||||||
|
|
||||||
@ -72,13 +73,145 @@
|
|||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static ewol::key::Special guiKeyBoardMode;
|
||||||
- (void)sendEvent:(NSEvent *)event {
|
|
||||||
EWOL_WARNING(" EVENT ... ");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
static int32_t getUniChar(NSEvent* theEvent) {
|
||||||
|
NSString *str = [theEvent charactersIgnoringModifiers];
|
||||||
|
// TODO : set if for every char in the string !!!
|
||||||
|
unichar c = [str characterAtIndex:0];
|
||||||
|
if (guiKeyBoardMode.getAlt() == false) {
|
||||||
|
return int32_t(c);
|
||||||
|
}
|
||||||
|
switch(c) {
|
||||||
|
case '(':
|
||||||
|
return int32_t('{');
|
||||||
|
case '5':
|
||||||
|
return int32_t('[');
|
||||||
|
case ')':
|
||||||
|
return int32_t('}');
|
||||||
|
case U'°':
|
||||||
|
return int32_t(']');
|
||||||
|
|
||||||
|
}
|
||||||
|
return int32_t(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)keyDown:(NSEvent *)theEvent {
|
||||||
|
bool thisIsAReapeateKey = false;
|
||||||
|
if ([theEvent isARepeat]) {
|
||||||
|
thisIsAReapeateKey = true;
|
||||||
|
}
|
||||||
|
int32_t c = getUniChar(theEvent);
|
||||||
|
EWOL_WARNING("KeyDown " << char(c));
|
||||||
|
MacOs::setKeyboard(guiKeyBoardMode, c, true, thisIsAReapeateKey);
|
||||||
|
if (true==thisIsAReapeateKey) {
|
||||||
|
MacOs::setKeyboard(guiKeyBoardMode, c, false, thisIsAReapeateKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)keyUp:(NSEvent *)theEvent {
|
||||||
|
bool thisIsAReapeateKey = false;
|
||||||
|
if ([theEvent isARepeat]) {
|
||||||
|
thisIsAReapeateKey = true;
|
||||||
|
}
|
||||||
|
int32_t c = getUniChar(theEvent);
|
||||||
|
EWOL_WARNING("KeyUp " << char(c));
|
||||||
|
MacOs::setKeyboard(guiKeyBoardMode, c, false, thisIsAReapeateKey);
|
||||||
|
if (true==thisIsAReapeateKey) {
|
||||||
|
MacOs::setKeyboard(guiKeyBoardMode, c, true, thisIsAReapeateKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)flagsChanged:(NSEvent *)theEvent {
|
||||||
|
if (([theEvent modifierFlags] & NSAlphaShiftKeyMask) != 0) {
|
||||||
|
EWOL_WARNING("NSAlphaShiftKeyMask");
|
||||||
|
if (guiKeyBoardMode.getCapsLock() == false) {
|
||||||
|
guiKeyBoardMode.setCapsLock(true);
|
||||||
|
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardCapLock, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (guiKeyBoardMode.getCapsLock() == true) {
|
||||||
|
guiKeyBoardMode.setCapsLock(false);
|
||||||
|
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardCapLock, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (([theEvent modifierFlags] & NSShiftKeyMask) != 0) {
|
||||||
|
EWOL_WARNING("NSShiftKeyMask");
|
||||||
|
if (guiKeyBoardMode.getShift() == false) {
|
||||||
|
guiKeyBoardMode.setShift(true);
|
||||||
|
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardShiftLeft, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (guiKeyBoardMode.getShift() == true) {
|
||||||
|
guiKeyBoardMode.setShift(false);
|
||||||
|
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardShiftLeft, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (([theEvent modifierFlags] & NSControlKeyMask) != 0) {
|
||||||
|
EWOL_WARNING("NSControlKeyMask");
|
||||||
|
if (guiKeyBoardMode.getCtrl() == false) {
|
||||||
|
guiKeyBoardMode.setCtrl(true);
|
||||||
|
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardCtrlLeft, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (guiKeyBoardMode.getCtrl() == true) {
|
||||||
|
guiKeyBoardMode.setCtrl(false);
|
||||||
|
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardCtrlLeft, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (([theEvent modifierFlags] & NSAlternateKeyMask) != 0) {
|
||||||
|
EWOL_WARNING("NSAlternateKeyMask");
|
||||||
|
if (guiKeyBoardMode.getAlt() == false) {
|
||||||
|
guiKeyBoardMode.setAlt(true);
|
||||||
|
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardAlt, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (guiKeyBoardMode.getAlt() == true) {
|
||||||
|
guiKeyBoardMode.setAlt(false);
|
||||||
|
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardAlt, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (([theEvent modifierFlags] & NSCommandKeyMask) != 0) {
|
||||||
|
EWOL_WARNING("NSCommandKeyMask");
|
||||||
|
if (guiKeyBoardMode.getMeta() == false) {
|
||||||
|
guiKeyBoardMode.setMeta(true);
|
||||||
|
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardMetaLeft, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (guiKeyBoardMode.getMeta() == true) {
|
||||||
|
guiKeyBoardMode.setMeta(false);
|
||||||
|
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardMetaLeft, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (([theEvent modifierFlags] & NSNumericPadKeyMask) != 0) {
|
||||||
|
EWOL_WARNING("NSNumericPadKeyMask");
|
||||||
|
if (guiKeyBoardMode.getNumLock() == false) {
|
||||||
|
guiKeyBoardMode.setNumLock(true);
|
||||||
|
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardNumLock, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (guiKeyBoardMode.getNumLock() == true) {
|
||||||
|
guiKeyBoardMode.setNumLock(false);
|
||||||
|
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardNumLock, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (([theEvent modifierFlags] & NSHelpKeyMask) != 0) {
|
||||||
|
EWOL_WARNING("NSHelpKeyMask");
|
||||||
|
}
|
||||||
|
if (([theEvent modifierFlags] & NSFunctionKeyMask) != 0) {
|
||||||
|
EWOL_WARNING("NSFunctionKeyMask");
|
||||||
|
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardContextMenu, true);
|
||||||
|
MacOs::setKeyboardMove(guiKeyBoardMode, ewol::key::keyboardContextMenu, false);
|
||||||
|
}
|
||||||
|
EWOL_WARNING("EVENT : " << int32_t([theEvent modifierFlags]));
|
||||||
|
}
|
||||||
|
|
||||||
// this generate all the event entry availlable ==> like a big keep focus ...
|
// this generate all the event entry availlable ==> like a big keep focus ...
|
||||||
- (BOOL)acceptsFirstResponder {
|
- (BOOL)acceptsFirstResponder {
|
||||||
return YES;
|
return YES;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user