[DEBUG] really better port for MacOs

This commit is contained in:
Edouard DUPIN 2017-08-10 21:02:25 +02:00
parent fa325e7d3d
commit 6e2eea031a
7 changed files with 461 additions and 329 deletions

View File

@ -91,9 +91,9 @@ class MacOSInterface : public gale::Context {
move = gale::key::keyboard::right;
break;
}
OS_setKeyboard(_special, move, (_isDown==false?gale::key::status::down:gale::key::status::up), _isAReapeateKey);
OS_setKeyboard(_special, move, (_isDown==true?gale::key::status::down:gale::key::status::up), _isAReapeateKey);
} else {
OS_setKeyboard(_special, gale::key::keyboard::character, (_isDown==false?gale::key::status::down:gale::key::status::up), _isAReapeateKey, _unichar);
OS_setKeyboard(_special, gale::key::keyboard::character, (_isDown==true?gale::key::status::down:gale::key::status::up), _isAReapeateKey, _unichar);
}
}
void MAC_SetKeyboardMove(gale::key::Special& _special,

View File

@ -6,6 +6,7 @@
#import <Cocoa/Cocoa.h>
#import <gale/context/MacOs/OpenglView.hpp>
#include <gale/key/key.hpp>
@interface GaleMainWindows : NSWindow {
OpenGLView* _view;
@ -32,6 +33,15 @@
- (void)flagsChanged:(NSEvent *)theEvent;
- (void)closeRequestGale;
- (void)UpdateScreenRequested;
/**
* @brief Check if we have the need to change the internal flag of shift, ctrl ...
* @param[in] bitField MacOs bit field
* @param[in] flags Patern to check
* @param[in] key Gale key
*/
- (void)flagsUpdate:(uint32_t) bitField
:(uint32_t) flags
:(enum gale::key::keyboard) key;
@end

View File

@ -28,38 +28,27 @@
GALE_DEBUG("INIT ...");
// set the windows at a specific position :
[windowsID cascadeTopLeftFromPoint:NSMakePoint(50,50)];
GALE_DEBUG("ALLOCATE ...");
// set the windows resizable
#ifdef __MAC_10_12
[windowsID setStyleMask:[windowsID styleMask] | NSWindowStyleMaskResizable];
#else
[windowsID setStyleMask:[windowsID styleMask] | NSResizableWindowMask];
#endif
GALE_DEBUG("ALLOCATE ...");
// oposite : [window setStyleMask:[window styleMask] & ~NSResizableWindowMask];
// set the title
id appName = [[NSProcessInfo processInfo] processName];
GALE_DEBUG("ALLOCATE ...");
[windowsID setTitle:appName];
GALE_DEBUG("ALLOCATE ...");
[windowsID setAcceptsMouseMovedEvents:YES];
GALE_DEBUG("ALLOCATE ...");
// ???
[windowsID makeKeyAndOrderFront:nil];
GALE_DEBUG("ALLOCATE ...");
[NSApp activateIgnoringOtherApps:YES];
GALE_DEBUG("ALLOCATE ...");
NSRect window_frame = [windowsID frame];
GALE_DEBUG("ALLOCATE ...");
_view=[[OpenGLView alloc]initWithFrame:window_frame]; //NSMakeRect(0, 0, 800, 600)];
GALE_DEBUG("ALLOCATE ...");
[windowsID setContentView:_view];
GALE_DEBUG("ALLOCATE ...");
[_view setAutoresizesSubviews:YES];
GALE_DEBUG("ALLOCATE ...");
// Override point for customization after application launch.
//[window addSubview:view];
@ -67,7 +56,6 @@
//[window makeKeyAndVisible];
//[windowsID setDelegate:view];
GALE_DEBUG("ALLOCATE ...");
return windowsID;
}
@ -84,32 +72,44 @@
static gale::key::Special guiKeyBoardMode;
static std::vector<std::pair<uint16_t,unichar>> g_listlasteventDown;
-(void)localKeyEvent:(NSEvent*)theEvent isDown:(bool)_isDown {
bool thisIsAReapeateKey = false;
if ([theEvent isARepeat]) {
thisIsAReapeateKey = true;
}
//[self flagsChanged:theEvent];
NSString *str = [theEvent charactersIgnoringModifiers];
// TODO : set if for every char in the string !!!
unichar c = [str characterAtIndex:0];
GALE_VERBOSE("Key Event " << c << " = '" << char(c) << "' isDown=" << _isDown);
uint16_t keycode = [theEvent keyCode];
// special case for \t + shift:
if ( guiKeyBoardMode.getShift() == true
&& c == 25) {
// We remap it to the correct tabulation.
c = 9;
}
GALE_WARNING("Key Event " << c << " = '" << char(c) << "' isDown=" << _isDown << " keycode=" << keycode);
bool find = true;
enum gale::key::keyboard keyInput;
switch (c) {
case 63232: keyInput = gale::key::keyboard::up; break;
case 63233: keyInput = gale::key::keyboard::down; break;
case 63234: keyInput = gale::key::keyboard::left; break;
case 63235: keyInput = gale::key::keyboard::right; break;
case 63276: keyInput = gale::key::keyboard::pageUp; break;
case 63277: keyInput = gale::key::keyboard::pageDown; break;
case 63273: keyInput = gale::key::keyboard::start; break;
case 63275: keyInput = gale::key::keyboard::end; break;
/*
case 78: keyInput = gale::key::keyboard::stopDefil; break;
case 127: keyInput = gale::key::keyboard::wait; break;
*/
case NSUpArrowFunctionKey: keyInput = gale::key::keyboard::up; break;
case NSDownArrowFunctionKey: keyInput = gale::key::keyboard::down; break;
case NSLeftArrowFunctionKey: keyInput = gale::key::keyboard::left; break;
case NSRightArrowFunctionKey: keyInput = gale::key::keyboard::right; break;
case NSPageUpFunctionKey: keyInput = gale::key::keyboard::pageUp; break;
case NSPageDownFunctionKey: keyInput = gale::key::keyboard::pageDown; break;
case NSBeginFunctionKey:
case NSHomeFunctionKey: keyInput = gale::key::keyboard::start; break;
case NSEndFunctionKey: keyInput = gale::key::keyboard::end; break;
case NSScrollLockFunctionKey: keyInput = gale::key::keyboard::stopDefil; break;
case NSPauseFunctionKey: keyInput = gale::key::keyboard::wait; break;
case NSPrintScreenFunctionKey: keyInput = gale::key::keyboard::print; break;
case 16: keyInput = gale::key::keyboard::contextMenu; break;
case 63302:
case NSInsertFunctionKey:
find = false;
keyInput = gale::key::keyboard::insert;
if(_isDown == false) {
@ -125,19 +125,44 @@ static gale::key::Special guiKeyBoardMode;
MacOs::setKeyboardMove(guiKeyBoardMode, keyInput, false, thisIsAReapeateKey);
break;
//case 84: keyInput = gale::key::keyboardCenter; break; // Keypad
case 63236: keyInput = gale::key::keyboard::f1; break;
case 63237: keyInput = gale::key::keyboard::f2; break;
case 63238: keyInput = gale::key::keyboard::f3; break;
case 63239: keyInput = gale::key::keyboard::f4; break;
case 63240: keyInput = gale::key::keyboard::f5; break;
case 63241: keyInput = gale::key::keyboard::f6; break;
case 63242: keyInput = gale::key::keyboard::f7; break;
case 63243: keyInput = gale::key::keyboard::f8; break;
case 63244: keyInput = gale::key::keyboard::f9; break;
case 63245: keyInput = gale::key::keyboard::f10; break;
case 63246: keyInput = gale::key::keyboard::f11; break;
case 63247: keyInput = gale::key::keyboard::f12; break;
case 63272: // Suppress
case NSF1FunctionKey: keyInput = gale::key::keyboard::f1; break;
case NSF2FunctionKey: keyInput = gale::key::keyboard::f2; break;
case NSF3FunctionKey: keyInput = gale::key::keyboard::f3; break;
case NSF4FunctionKey: keyInput = gale::key::keyboard::f4; break;
case NSF5FunctionKey: keyInput = gale::key::keyboard::f5; break;
case NSF6FunctionKey: keyInput = gale::key::keyboard::f6; break;
case NSF7FunctionKey: keyInput = gale::key::keyboard::f7; break;
case NSF8FunctionKey: keyInput = gale::key::keyboard::f8; break;
case NSF9FunctionKey: keyInput = gale::key::keyboard::f9; break;
case NSF10FunctionKey: keyInput = gale::key::keyboard::f10; break;
case NSF11FunctionKey: keyInput = gale::key::keyboard::f11; break;
case NSF12FunctionKey: keyInput = gale::key::keyboard::f12; break;
case NSF13FunctionKey:
case NSF14FunctionKey:
case NSF15FunctionKey:
case NSF16FunctionKey:
case NSF17FunctionKey:
case NSF18FunctionKey:
case NSF19FunctionKey:
case NSF20FunctionKey:
case NSF21FunctionKey:
case NSF22FunctionKey:
case NSF23FunctionKey:
case NSF24FunctionKey:
case NSF25FunctionKey:
case NSF26FunctionKey:
case NSF27FunctionKey:
case NSF28FunctionKey:
case NSF29FunctionKey:
case NSF30FunctionKey:
case NSF31FunctionKey:
case NSF32FunctionKey:
case NSF33FunctionKey:
case NSF34FunctionKey:
case NSF35FunctionKey:
find = false;
break;
case NSDeleteFunctionKey: // Suppress
find = false;
MacOs::setKeyboard(guiKeyBoardMode, u32char::Delete, _isDown, thisIsAReapeateKey);
if (true == thisIsAReapeateKey) {
@ -151,10 +176,36 @@ static gale::key::Special guiKeyBoardMode;
// special keyboard transcription ...
str = [theEvent characters];
c = [str characterAtIndex:0];
}
GALE_VERBOSE("Key Event ALT " << c << " = '" << char(c) << "' isDown=" << _isDown << " nb in list=" << g_listlasteventDown.size());
} else {
GALE_VERBOSE("Key Event " << c << " = '" << char(c) << "' isDown=" << _isDown);
}
// MacOs have a problem of synchronizing the correct key with the modifier...
if (_isDown == false) {
for (auto it = g_listlasteventDown.begin();
it != g_listlasteventDown.end();
++it) {
if (it->first == keycode) {
c = it->second;
g_listlasteventDown.erase(it);
GALE_VERBOSE("Key Event " << c << " = '" << char(c) << "' isDown=" << _isDown << " (override)");
break;
}
}
} else {
// remove a previous occurence of this element (case where Macos does not send the UP)...
for (auto it = g_listlasteventDown.begin();
it != g_listlasteventDown.end();
++it) {
if (it->first == keycode) {
g_listlasteventDown.erase(it);
break;
}
}
g_listlasteventDown.push_back(std::make_pair(keycode, c));
}
MacOs::setKeyboard(guiKeyBoardMode, c, _isDown, thisIsAReapeateKey);
if (true==thisIsAReapeateKey) {
if (thisIsAReapeateKey == true) {
MacOs::setKeyboard(guiKeyBoardMode, c, !_isDown, thisIsAReapeateKey);
}
}
@ -178,127 +229,76 @@ static gale::key::Special guiKeyBoardMode;
[self localKeyEvent:theEvent isDown:false];
}
- (void)flagsUpdate:(uint32_t) bitField
:(uint32_t) flags
:(enum gale::key::keyboard) key {
if ((bitField & flags) != 0) {
GALE_VERBOSE("Flag change: " << key);
if (guiKeyBoardMode.get(key) == false) {
GALE_WARNING(" " << key << " DOWN");
guiKeyBoardMode.update(key, true);
MacOs::setKeyboardMove(guiKeyBoardMode, key, true, false);
}
} else {
if (guiKeyBoardMode.get(key) == true) {
GALE_WARNING(" " << key << " UP");
guiKeyBoardMode.update(key, false);
MacOs::setKeyboardMove(guiKeyBoardMode, key, false, false);
}
}
}
- (void)flagsChanged:(NSEvent *)theEvent {
uint32_t bitField = [theEvent modifierFlags];
GALE_ERROR("flagsChanged : " << std::hex << [theEvent modifierFlags]);
#ifdef __MAC_10_12
if (([theEvent modifierFlags] & NSEventModifierFlagCapsLock) != 0) {
[self flagsUpdate:bitField: NSEventModifierFlagCapsLock: gale::key::keyboard::capLock];
#else
if (([theEvent modifierFlags] & NSAlphaShiftKeyMask) != 0) {
[self flagsUpdate:bitField: NSAlphaShiftKeyMask: gale::key::keyboard::capLock];
#endif
GALE_VERBOSE("NSEventModifierFlagCapsLock");
if (guiKeyBoardMode.getCapsLock() == false) {
guiKeyBoardMode.setCapsLock(true);
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::capLock, true, false);
}
} else {
if (guiKeyBoardMode.getCapsLock() == true) {
guiKeyBoardMode.setCapsLock(false);
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::capLock, false, false);
}
}
#ifdef __MAC_10_12
if (([theEvent modifierFlags] & NSEventModifierFlagShift) != 0) {
//[self flagsUpdate:bitField: NSEventModifierFlagShift: gale::key::keyboard::shiftLeft];
[self flagsUpdate:bitField: 0x02: gale::key::keyboard::shiftLeft];
[self flagsUpdate:bitField: 0x04: gale::key::keyboard::shiftRight];
#else
if (([theEvent modifierFlags] & NSShiftKeyMask) != 0) {
[self flagsUpdate:bitField: NSShiftKeyMask: gale::key::keyboard::shiftLeft];
#endif
GALE_VERBOSE("NSEventModifierFlagShift");
if (guiKeyBoardMode.getShift() == false) {
guiKeyBoardMode.setShift(true);
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::shiftLeft, true, false);
}
} else {
if (guiKeyBoardMode.getShift() == true) {
guiKeyBoardMode.setShift(false);
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::shiftLeft, false, false);
}
}
#ifdef __MAC_10_12
if (([theEvent modifierFlags] & NSEventModifierFlagControl) != 0) {
//[self flagsUpdate:bitField: NSEventModifierFlagControl: gale::key::keyboard::ctrlLeft];
[self flagsUpdate:bitField: 0x0001: gale::key::keyboard::ctrlLeft];
[self flagsUpdate:bitField: 0x2000: gale::key::keyboard::ctrlRight];
#else
if (([theEvent modifierFlags] & NSControlKeyMask) != 0) {
[self flagsUpdate:bitField: NSControlKeyMask: gale::key::keyboard::ctrlLeft];
#endif
//GALE_VERBOSE("NSEventModifierFlagControl");
if (guiKeyBoardMode.getCtrl() == false) {
GALE_VERBOSE("NSEventModifierFlagControl DOWN");
guiKeyBoardMode.setCtrl(true);
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::ctrlLeft, true, false);
}
} else {
if (guiKeyBoardMode.getCtrl() == true) {
GALE_VERBOSE("NSEventModifierFlagControl UP");
guiKeyBoardMode.setCtrl(false);
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::ctrlLeft, false, false);
}
}
#ifdef __MAC_10_12
if (([theEvent modifierFlags] & NSEventModifierFlagOption) != 0) {
//[self flagsUpdate:bitField: NSEventModifierFlagOption: gale::key::keyboard::altLeft];
[self flagsUpdate:bitField: 0x0020: gale::key::keyboard::altLeft];
[self flagsUpdate:bitField: 0x0040: gale::key::keyboard::altRight];
#else
if (([theEvent modifierFlags] & NSAlternateKeyMask) != 0) {
[self flagsUpdate:bitField: NSAlternateKeyMask: gale::key::keyboard::altLeft];
#endif
GALE_VERBOSE("NSEventModifierFlagOption");
if (guiKeyBoardMode.getAlt() == false) {
guiKeyBoardMode.setAlt(true);
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::alt, true, false);
}
} else {
if (guiKeyBoardMode.getAlt() == true) {
guiKeyBoardMode.setAlt(false);
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::alt, false, false);
}
}
#ifdef __MAC_10_12
if (([theEvent modifierFlags] & NSEventModifierFlagCommand) != 0) {
//[self flagsUpdate:bitField: NSEventModifierFlagCommand: gale::key::keyboard::metaLeft];
[self flagsUpdate:bitField: 0x0008: gale::key::keyboard::metaLeft];
[self flagsUpdate:bitField: 0x0010: gale::key::keyboard::metaRight];
#else
if (([theEvent modifierFlags] & NSCommandKeyMask) != 0) {
[self flagsUpdate:bitField: NSCommandKeyMask: gale::key::keyboard::metaLeft];
#endif
GALE_VERBOSE("NSEventModifierFlagCommand");
if (guiKeyBoardMode.getMeta() == false) {
guiKeyBoardMode.setMeta(true);
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::metaLeft, true, false);
}
} else {
if (guiKeyBoardMode.getMeta() == true) {
guiKeyBoardMode.setMeta(false);
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::metaLeft, false, false);
}
}
#ifdef __MAC_10_12
if (([theEvent modifierFlags] & NSEventModifierFlagNumericPad) != 0) {
[self flagsUpdate:bitField: NSEventModifierFlagNumericPad: gale::key::keyboard::numLock];
#else
if (([theEvent modifierFlags] & NSNumericPadKeyMask) != 0) {
[self flagsUpdate:bitField: NSNumericPadKeyMask: gale::key::keyboard::numLock];
#endif
GALE_VERBOSE("NSEventModifierFlagNumericPad");
if (guiKeyBoardMode.getNumLock() == false) {
guiKeyBoardMode.setNumLock(true);
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::numLock, true, false);
}
} else {
if (guiKeyBoardMode.getNumLock() == true) {
guiKeyBoardMode.setNumLock(false);
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::numLock, false, false);
}
}
#ifdef __MAC_10_12
if (([theEvent modifierFlags] & NSEventModifierFlagHelp) != 0) {
if ((bitField & NSEventModifierFlagFunction) != 0) {
#else
if (([theEvent modifierFlags] & NSHelpKeyMask) != 0) {
if ((bitField & NSFunctionKeyMask) != 0) {
#endif
GALE_VERBOSE("NSEventModifierFlagHelp");
}
#ifdef __MAC_10_12
if (([theEvent modifierFlags] & NSEventModifierFlagFunction) != 0) {
#else
if (([theEvent modifierFlags] & NSFunctionKeyMask) != 0) {
#endif
GALE_VERBOSE("NSEventModifierFlagFunction");
GALE_WARNING("NSEventModifierFlagFunction");
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::contextMenu, true, false);
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::contextMenu, false, false);
}
GALE_VERBOSE("EVENT : " << int32_t([theEvent modifierFlags]));
GALE_WARNING(" ==> new state special: " << etk::to_string(guiKeyBoardMode));
}
// this generate all the event entry availlable ==> like a big keep focus ...

View File

@ -8,13 +8,21 @@
#include <etk/stdTools.hpp>
#define GALE_FLAG_KEY_CAPS_LOCK 0x00000001
#define GALE_FLAG_KEY_SHIFT 0x00000002
#define GALE_FLAG_KEY_CTRL 0x00000004
#define GALE_FLAG_KEY_META 0x00000008
#define GALE_FLAG_KEY_ALT 0x00000010
#define GALE_FLAG_KEY_ALTGR 0x00000020
#define GALE_FLAG_KEY_NUM_LOCK 0x00000040
#define GALE_FLAG_KEY_INSERT 0x00000080
#define GALE_FLAG_KEY_SHIFT 0x00000030
#define GALE_FLAG_KEY_SHIFT_LEFT 0x80000010
#define GALE_FLAG_KEY_SHIFT_RIGHT 0x40000020
#define GALE_FLAG_KEY_CTRL 0x00000300
#define GALE_FLAG_KEY_CTRL_LEFT 0x00000100
#define GALE_FLAG_KEY_CTRL_RIGHT 0x00000200
#define GALE_FLAG_KEY_META 0x00003000
#define GALE_FLAG_KEY_META_LEFT 0x00001000
#define GALE_FLAG_KEY_META_RIGHT 0x00002000
#define GALE_FLAG_KEY_ALT 0x00030000
#define GALE_FLAG_KEY_ALT_LEFT 0x00010000
#define GALE_FLAG_KEY_ALT_RIGHT 0x00020000
#define GALE_FLAG_KEY_ALTGR 0x00020000
#define GALE_FLAG_KEY_NUM_LOCK 0x00000002
#define GALE_FLAG_KEY_INSERT 0x00000003
// TODO : Update to support the Left and right of some key ...
@ -31,22 +39,28 @@ void gale::key::Special::update(enum gale::key::keyboard _move, bool _isDown) {
setCapsLock(_isDown);
break;
case keyboard::shiftLeft:
setShiftLeft(_isDown);
break;
case keyboard::shiftRight:
setShift(_isDown);
setShiftRight(_isDown);
break;
case keyboard::ctrlLeft:
setCtrlLeft(_isDown);
break;
case keyboard::ctrlRight:
setCtrl(_isDown);
setCtrlRight(_isDown);
break;
case keyboard::metaLeft:
setMetaLeft(_isDown);
break;
case keyboard::metaRight:
setMeta(_isDown);
setMetaRight(_isDown);
break;
case keyboard::alt:
setAlt(_isDown);
case keyboard::altLeft:
setAltLeft(_isDown);
break;
case keyboard::altGr:
setAltGr(_isDown);
case keyboard::altRight:
setAltRight(_isDown);
break;
case keyboard::numLock:
setNumLock(_isDown);
@ -56,148 +70,138 @@ void gale::key::Special::update(enum gale::key::keyboard _move, bool _isDown) {
}
}
bool gale::key::Special::getCapsLock() const {
if ((m_value & GALE_FLAG_KEY_CAPS_LOCK) != 0) {
return true;
bool gale::key::Special::get(enum gale::key::keyboard _move) {
switch (_move) {
case keyboard::insert:
return getInsert();
case keyboard::capLock:
return getCapsLock();
case keyboard::shiftLeft:
return getShiftLeft();
case keyboard::shiftRight:
return getShiftRight();
case keyboard::ctrlLeft:
return getCtrlLeft();
case keyboard::ctrlRight:
return getCtrlRight();
case keyboard::metaLeft:
return getMetaLeft();
case keyboard::metaRight:
return getMetaRight();
case keyboard::altRight:
return getAltLeft();
case keyboard::altLeft:
return getAltRight();
case keyboard::numLock:
return getNumLock();
default:
break;
}
return false;
}
void gale::key::Special::setCapsLock(bool _value) {
if ((m_value & GALE_FLAG_KEY_CAPS_LOCK) != 0) {
if (_value == false) {
m_value -= GALE_FLAG_KEY_CAPS_LOCK;
void gale::key::Special::setFlag(uint32_t _flag, bool _isDown) {
if ((m_value & _flag) != 0) {
if (_isDown == false) {
m_value -= _flag;
}
} else {
if (_value == true) {
m_value += GALE_FLAG_KEY_CAPS_LOCK;
if (_isDown == true) {
m_value += _flag;
}
}
}
bool gale::key::Special::getFlag(uint32_t _flag) const {
if ((m_value & _flag) != 0) {
return true;
}
return false;
};
bool gale::key::Special::getCapsLock() const {
return getFlag(GALE_FLAG_KEY_CAPS_LOCK);
}
void gale::key::Special::setCapsLock(bool _value) {
setFlag(GALE_FLAG_KEY_CAPS_LOCK, _value);
}
bool gale::key::Special::getShift() const {
if ((m_value & GALE_FLAG_KEY_SHIFT) != 0) {
return true;
return getFlag(GALE_FLAG_KEY_SHIFT);
}
return false;
bool gale::key::Special::getShiftLeft() const {
return getFlag(GALE_FLAG_KEY_SHIFT_LEFT);
}
void gale::key::Special::setShift(bool _value) {
if ((m_value & GALE_FLAG_KEY_SHIFT) != 0) {
if (_value == false) {
m_value -= GALE_FLAG_KEY_SHIFT;
}
} else {
if (_value == true) {
m_value += GALE_FLAG_KEY_SHIFT;
bool gale::key::Special::getShiftRight() const {
return getFlag(GALE_FLAG_KEY_SHIFT_RIGHT);
}
void gale::key::Special::setShiftLeft(bool _value) {
setFlag(GALE_FLAG_KEY_SHIFT_LEFT, _value);
}
void gale::key::Special::setShiftRight(bool _value) {
setFlag(GALE_FLAG_KEY_SHIFT_RIGHT, _value);
}
bool gale::key::Special::getCtrl() const {
if ((m_value & GALE_FLAG_KEY_CTRL) != 0) {
return true;
return getFlag(GALE_FLAG_KEY_CTRL);
}
return false;
bool gale::key::Special::getCtrlLeft() const {
return getFlag(GALE_FLAG_KEY_CTRL_LEFT);
}
void gale::key::Special::setCtrl(bool _value) {
if ((m_value & GALE_FLAG_KEY_CTRL) != 0) {
if (_value == false) {
m_value -= GALE_FLAG_KEY_CTRL;
}
} else {
if (_value == true) {
m_value += GALE_FLAG_KEY_CTRL;
bool gale::key::Special::getCtrlRight() const {
return getFlag(GALE_FLAG_KEY_CTRL_RIGHT);
}
void gale::key::Special::setCtrlLeft(bool _value) {
setFlag(GALE_FLAG_KEY_CTRL_LEFT, _value);
}
void gale::key::Special::setCtrlRight(bool _value) {
setFlag(GALE_FLAG_KEY_CTRL_RIGHT, _value);
}
bool gale::key::Special::getMeta() const {
if ((m_value & GALE_FLAG_KEY_META) != 0) {
return true;
return getFlag(GALE_FLAG_KEY_META);
}
return false;
bool gale::key::Special::getMetaLeft() const {
return getFlag(GALE_FLAG_KEY_META_LEFT);
}
void gale::key::Special::setMeta(bool _value) {
if ((m_value & GALE_FLAG_KEY_META) != 0) {
if (_value == false) {
m_value -= GALE_FLAG_KEY_META;
}
} else {
if (_value == true) {
m_value += GALE_FLAG_KEY_META;
bool gale::key::Special::getMetaRight() const {
return getFlag(GALE_FLAG_KEY_META_RIGHT);
}
void gale::key::Special::setMetaLeft(bool _value) {
setFlag(GALE_FLAG_KEY_META_LEFT, _value);
}
void gale::key::Special::setMetaRight(bool _value) {
setFlag(GALE_FLAG_KEY_META_RIGHT, _value);
}
bool gale::key::Special::getAlt() const {
if ((m_value & GALE_FLAG_KEY_ALT) != 0) {
return true;
return getFlag(GALE_FLAG_KEY_ALT);
}
return false;
bool gale::key::Special::getAltLeft() const {
return getFlag(GALE_FLAG_KEY_ALT_LEFT);
}
void gale::key::Special::setAlt(bool _value) {
if ((m_value & GALE_FLAG_KEY_ALT) != 0) {
if (_value == false) {
m_value -= GALE_FLAG_KEY_ALT;
}
} else {
if (_value == true) {
m_value += GALE_FLAG_KEY_ALT;
}
}
}
bool gale::key::Special::getAltGr() const {
if ((m_value & GALE_FLAG_KEY_ALTGR) != 0) {
return true;
}
return false;
}
void gale::key::Special::setAltGr(bool _value) {
if ((m_value & GALE_FLAG_KEY_ALTGR) != 0) {
if (_value == false) {
m_value -= GALE_FLAG_KEY_ALTGR;
}
} else {
if (_value == true) {
m_value += GALE_FLAG_KEY_ALTGR;
bool gale::key::Special::getAltRight() const {
return getFlag(GALE_FLAG_KEY_ALT_RIGHT);
}
void gale::key::Special::setAltLeft(bool _value) {
setFlag(GALE_FLAG_KEY_ALT_LEFT, _value);
}
void gale::key::Special::setAltRight(bool _value) {
setFlag(GALE_FLAG_KEY_ALT_RIGHT, _value);
}
bool gale::key::Special::getNumLock() const {
if ((m_value & GALE_FLAG_KEY_NUM_LOCK) != 0) {
return true;
}
return false;
return getFlag(GALE_FLAG_KEY_NUM_LOCK);
}
void gale::key::Special::setNumLock(bool _value) {
if ((m_value & GALE_FLAG_KEY_NUM_LOCK) != 0) {
if (_value == false) {
m_value -= GALE_FLAG_KEY_NUM_LOCK;
}
} else {
if (_value == true) {
m_value += GALE_FLAG_KEY_NUM_LOCK;
}
}
setFlag(GALE_FLAG_KEY_NUM_LOCK, _value);
}
bool gale::key::Special::getInsert() const {
if ((m_value & GALE_FLAG_KEY_INSERT) != 0) {
return true;
}
return false;
return getFlag(GALE_FLAG_KEY_INSERT);
}
void gale::key::Special::setInsert(bool _value) {
if ((m_value & GALE_FLAG_KEY_INSERT) != 0) {
if (_value == false) {
m_value -= GALE_FLAG_KEY_INSERT;
}
} else {
if (_value == true) {
m_value += GALE_FLAG_KEY_INSERT;
}
}
setFlag(GALE_FLAG_KEY_INSERT, _value);
}
std::ostream& gale::key::operator <<(std::ostream& _os, const gale::key::Special& _obj) {
@ -206,7 +210,6 @@ std::ostream& gale::key::operator <<(std::ostream& _os, const gale::key::Special
_os << " ctrl=" << _obj.getCtrl();
_os << " meta=" << _obj.getMeta();
_os << " alt=" << _obj.getAlt();
_os << " altGr=" << _obj.getAltGr();
_os << " verNum=" << _obj.getNumLock();
_os << " insert=" << _obj.getInsert();
return _os;
@ -223,30 +226,44 @@ namespace etk {
out += "|";
}
out += "SHIFT";
if (_obj.getShiftLeft() == false) {
out += "-RIGHT";
} else if (_obj.getShiftRight() == false) {
out += "-LEFT";
}
}
if (_obj.getCtrl() == true) {
if (out.size() > 0) {
out += "|";
}
out += "CTRL";
if (_obj.getCtrlLeft() == false) {
out += "-RIGHT";
} else if (_obj.getCtrlRight() == false) {
out += "-LEFT";
}
}
if (_obj.getMeta() == true) {
if (out.size() > 0) {
out += "|";
}
out += "META";
if (_obj.getMetaLeft() == false) {
out += "-RIGHT";
} else if (_obj.getMetaRight() == false) {
out += "-LEFT";
}
}
if (_obj.getAlt() == true) {
if (out.size() > 0) {
out += "|";
}
out += "ALT";
if (_obj.getAltLeft() == false) {
out += "-RIGHT";
} else if (_obj.getAltRight() == false) {
out += "-LEFT";
}
if (_obj.getAltGr() == true) {
if (out.size() > 0) {
out += "|";
}
out += "ALTGR";
}
if (_obj.getNumLock() == true) {
if (out.size() > 0) {
@ -269,15 +286,33 @@ namespace etk {
if (it == "CAPS") {
out.setCapsLock(true);
} else if (it == "SHIFT") {
out.setShift(true);
out.setShiftLeft(true);
out.setShiftRight(true);
} else if (it == "SHIFT-LEFT") {
out.setShiftLeft(true);
} else if (it == "SHIFT-RIGHT") {
out.setShiftRight(true);
} else if (it == "CTRL") {
out.setCtrl(true);
out.setCtrlLeft(true);
out.setCtrlRight(true);
} else if (it == "CTRL-LEFT") {
out.setCtrlLeft(true);
} else if (it == "CTRL-RIGHT") {
out.setCtrlRight(true);
} else if (it == "META") {
out.setMeta(true);
out.setMetaLeft(true);
out.setMetaRight(true);
} else if (it == "META-LEFT") {
out.setMetaLeft(true);
} else if (it == "META-RIGHT") {
out.setMetaRight(true);
} else if (it == "ALT") {
out.setAlt(true);
} else if (it == "ALTGR") {
out.setAltGr(true);
out.setAltLeft(true);
out.setAltRight(true);
} else if (it == "ALT-LEFT") {
out.setAltLeft(true);
} else if (it == "ALT-RIGHT") {
out.setAltRight(true);
} else if (it == "NUM_LOCK") {
out.setNumLock(true);
} else if (it == "INSERT") {

View File

@ -37,50 +37,114 @@ namespace gale {
*/
bool getShift() const;
/**
* @brief Set the current Shift key status
* @brief Get the current Shift left key status
* @return The Shift value
*/
bool getShiftLeft() const;
/**
* @brief Get the current Shift right key status
* @return The Shift value
*/
bool getShiftRight() const;
/**
* @brief Set the current Shift left key status
* @param[in] _value The new Shift value
*/
void setShift(bool _value);
void setShiftLeft(bool _value);
/**
* @brief Set the current Shift right key status
* @param[in] _value The new Shift value
*/
void setShiftRight(bool _value);
/**
* @brief Get the Current Control key status
* @return The Control value
*/
bool getCtrl() const;
/**
* @brief Set the Current Control key status
* @brief Get the Current Control left key status
* @return The Control value
*/
bool getCtrlLeft() const;
/**
* @brief Get the Current Control right key status
* @return The Control value
*/
bool getCtrlRight() const;
/**
* @brief Set the Current Control left key status
* @param[in] _value The new Control value
*/
void setCtrl(bool _value);
void setCtrlLeft(bool _value);
/**
* @brief Set the Current Control right key status
* @param[in] _value The new Control value
*/
void setCtrlRight(bool _value);
/**
* @brief Get the current Meta key status (also named windows or apple key)
* @return The Meta value (name Windows key, apple key, command key ...)
*/
bool getMeta() const;
/**
* @brief Set the current Meta key status (also named windows or apple key)
* @brief Get the current Meta left key status (also named windows or apple key)
* @return The Meta value (name Windows key, apple key, command key ...)
*/
bool getMetaLeft() const;
/**
* @brief Get the current Meta right key status (also named windows or apple key)
* @return The Meta value (name Windows key, apple key, command key ...)
*/
bool getMetaRight() const;
/**
* @brief Set the current Meta left key status (also named windows or apple key)
* @param[in] _value The new Meta value (name Windows key, apple key, command key ...)
*/
void setMeta(bool _value);
void setMetaLeft(bool _value);
/**
* @brief Set the current Meta right key status (also named windows or apple key)
* @param[in] _value The new Meta value (name Windows key, apple key, command key ...)
*/
void setMetaRight(bool _value);
/**
* @brief Get the current Alt key status
* @return The Alt value
*/
bool getAlt() const;
/**
* @brief Set the current Alt key status
* @brief Get the current Alt left key status
* @return The Alt value
*/
bool getAltLeft() const;
/**
* @brief Get the current Alt right key status (alt-gr)
* @return The Alt value
*/
bool getAltRight() const;
/**
* @brief Set the current Alt left key status
* @param[in] _value The new Alt value
*/
void setAlt(bool _value);
void setAltLeft(bool _value);
/**
* @brief Set the current Alt right key status (alt-gr)
* @param[in] _value The new Alt value
*/
void setAltRight(bool _value);
/**
* @brief Get the current Alt-Gr key status
* @return The Alt-gr value (does not exist on MacOs)
*/
bool getAltGr() const;
bool getAltGr() const {
return getAltRight();
}
/**
* @brief Set the current Alt-Gr key status
* @param[in] _value The new Alt-gr value (does not exist on MacOs)
*/
void setAltGr(bool _value);
void setAltGr(bool _value) {
setAltRight(_value);
}
/**
* @brief Get the current Ver-num key status
* @return The Numerical Lock value
@ -104,9 +168,30 @@ namespace gale {
/**
* @brief Update the internal value with the input moving key.
* @param[in] _move Moving key.
* @param[in] _isFown The Key is pressed or not.
* @param[in] _isDown The key is pressed or not.
*/
void update(enum gale::key::keyboard _move, bool _isDown);
/**
* @brief Get the value with the input moving key.
* @param[in] _move Moving key.
* @return true The key is pressed.
* @return false The key is released.
*/
bool get(enum gale::key::keyboard _move);
protected:
/**
* @brief Set the internal value with the input moving FLAG.
* @param[in] _flag Moving Flag.
* @param[in] _isDown The key is pressed or not.
*/
void setFlag(uint32_t _flag, bool _isDown);
/**
* @brief Get the value with the input moving FLAG.
* @param[in] _flag Moving internal FLAG.
* @return true The key is pressed.
* @return false The key is released.
*/
bool getFlag(uint32_t _flag) const;
};
std::ostream& operator <<(std::ostream& _os, const gale::key::Special& _obj);
}

View File

@ -41,8 +41,8 @@ static const char* keyboardDescriptionString[] = {
"keyboard::ctrlRight",
"keyboard::metaLeft",
"keyboard::metaRight",
"keyboard::alt",
"keyboard::altGr",
"keyboard::altLeft",
"keyboard::altRight",
"keyboard::contextMenu",
"keyboard::numLock",
// harware section:

View File

@ -47,8 +47,10 @@ namespace gale {
ctrlRight, //!< Control right key.
metaLeft, //!< Meta left key (apple key or windows key).
metaRight, //!< Meta right key (apple key or windows key).
alt, //!< Alt key.
altGr, //!< Alt ground key.
altLeft, //!< Alt left key.
alt = altLeft, //!< Alt key. Same as altLeft.
altRight, //!< Alt right key.
altGr = altRight, //!< Alt ground key. Same as AltRight
contextMenu, //!< Contextual menu key.
numLock, //!< Numerical Lock key
// harware section: