Changed #947 improved shortcut and unicode text handling
This commit is contained in:
parent
84ffbd6c7f
commit
65fcd8f275
2 changed files with 72 additions and 19 deletions
|
@ -203,8 +203,8 @@ NLMISC::TKey virtualKeycodeToNelKey(unsigned short keycode)
|
||||||
case kVK_ANSI_Minus: return NLMISC::KeySUBTRACT;
|
case kVK_ANSI_Minus: return NLMISC::KeySUBTRACT;
|
||||||
case kVK_ANSI_RightBracket: return NLMISC::KeyRBRACKET;
|
case kVK_ANSI_RightBracket: return NLMISC::KeyRBRACKET;
|
||||||
case kVK_ANSI_LeftBracket: return NLMISC::KeyLBRACKET;
|
case kVK_ANSI_LeftBracket: return NLMISC::KeyLBRACKET;
|
||||||
case kVK_ANSI_Quote:break;
|
case kVK_ANSI_Quote: return NLMISC::KeyAPOSTROPHE;
|
||||||
case kVK_ANSI_Grave:break;
|
case kVK_ANSI_Grave: return NLMISC::KeyPARAGRAPH;
|
||||||
case kVK_ANSI_Slash: return NLMISC::KeySLASH;
|
case kVK_ANSI_Slash: return NLMISC::KeySLASH;
|
||||||
case kVK_ANSI_Backslash: return NLMISC::KeyBACKSLASH;
|
case kVK_ANSI_Backslash: return NLMISC::KeyBACKSLASH;
|
||||||
case kVK_ANSI_Comma: return NLMISC::KeyCOMMA;
|
case kVK_ANSI_Comma: return NLMISC::KeyCOMMA;
|
||||||
|
@ -231,15 +231,12 @@ NLMISC::TKey virtualKeycodeToNelKey(unsigned short keycode)
|
||||||
case kVK_Return: return NLMISC::KeyRETURN;
|
case kVK_Return: return NLMISC::KeyRETURN;
|
||||||
case kVK_Tab: return NLMISC::KeyTAB;
|
case kVK_Tab: return NLMISC::KeyTAB;
|
||||||
case kVK_Space: return NLMISC::KeySPACE;
|
case kVK_Space: return NLMISC::KeySPACE;
|
||||||
case kVK_Delete: return NLMISC::KeyDELETE;
|
case kVK_Delete: return NLMISC::KeyBACK;
|
||||||
case kVK_ForwardDelete:break;
|
case kVK_ForwardDelete: return NLMISC::KeyDELETE;
|
||||||
case kVK_Escape: return NLMISC::KeyESCAPE;
|
case kVK_Escape: return NLMISC::KeyESCAPE;
|
||||||
case kVK_Command:break;
|
|
||||||
case kVK_Shift: return NLMISC::KeySHIFT;
|
case kVK_Shift: return NLMISC::KeySHIFT;
|
||||||
case kVK_RightShift: return NLMISC::KeyRSHIFT;
|
case kVK_RightShift: return NLMISC::KeyRSHIFT;
|
||||||
case kVK_CapsLock: return NLMISC::KeyCAPITAL;
|
case kVK_CapsLock: return NLMISC::KeyCAPITAL;
|
||||||
case kVK_Option:break;
|
|
||||||
case kVK_RightOption:break;
|
|
||||||
case kVK_Control: return NLMISC::KeyCONTROL;
|
case kVK_Control: return NLMISC::KeyCONTROL;
|
||||||
case kVK_RightControl: return NLMISC::KeyRCONTROL;
|
case kVK_RightControl: return NLMISC::KeyRCONTROL;
|
||||||
case kVK_F1: return NLMISC::KeyF1;
|
case kVK_F1: return NLMISC::KeyF1;
|
||||||
|
@ -264,12 +261,15 @@ NLMISC::TKey virtualKeycodeToNelKey(unsigned short keycode)
|
||||||
case kVK_F20: return NLMISC::KeyF20;
|
case kVK_F20: return NLMISC::KeyF20;
|
||||||
case kVK_Home: return NLMISC::KeyHOME;
|
case kVK_Home: return NLMISC::KeyHOME;
|
||||||
case kVK_End: return NLMISC::KeyEND;
|
case kVK_End: return NLMISC::KeyEND;
|
||||||
case kVK_PageUp:break;
|
case kVK_PageUp: return NLMISC::KeyPRIOR;
|
||||||
case kVK_PageDown:break;
|
case kVK_PageDown: return NLMISC::KeyNEXT;
|
||||||
case kVK_LeftArrow: return NLMISC::KeyLEFT;
|
case kVK_LeftArrow: return NLMISC::KeyLEFT;
|
||||||
case kVK_RightArrow: return NLMISC::KeyRIGHT;
|
case kVK_RightArrow: return NLMISC::KeyRIGHT;
|
||||||
case kVK_DownArrow: return NLMISC::KeyDOWN;
|
case kVK_DownArrow: return NLMISC::KeyDOWN;
|
||||||
case kVK_UpArrow: return NLMISC::KeyUP;
|
case kVK_UpArrow: return NLMISC::KeyUP;
|
||||||
|
case kVK_Command:break;
|
||||||
|
case kVK_Option:break;
|
||||||
|
case kVK_RightOption:break;
|
||||||
case kVK_Function:break;
|
case kVK_Function:break;
|
||||||
case kVK_VolumeUp:break;
|
case kVK_VolumeUp:break;
|
||||||
case kVK_VolumeDown:break;
|
case kVK_VolumeDown:break;
|
||||||
|
@ -299,6 +299,58 @@ NLMISC::TKeyButton modifierFlagsToNelKeyButton(unsigned int modifierFlags)
|
||||||
return (NLMISC::TKeyButton)buttons;
|
return (NLMISC::TKeyButton)buttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isTextKeyEvent(NSEvent* event)
|
||||||
|
{
|
||||||
|
// if there are no characters provided with this event, is is not a text event
|
||||||
|
if([[event characters] length] == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
NLMISC::TKey nelKey = virtualKeycodeToNelKey([event keyCode]);
|
||||||
|
|
||||||
|
// ryzom ui wants to have "escape key string" to leave text box
|
||||||
|
if(nelKey == NLMISC::KeyESCAPE)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// ryzom ui wants to have "return key string" to submit text box (send chat)
|
||||||
|
if(nelKey == NLMISC::KeyRETURN)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// get the character reported by cocoa
|
||||||
|
unsigned int character = [[event characters] characterAtIndex:0];
|
||||||
|
|
||||||
|
// printable ascii characters
|
||||||
|
if(isprint(character))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO check why iswprint(character) does not solve it.
|
||||||
|
it always returns false, even for π é ...
|
||||||
|
*/
|
||||||
|
// > 127 but not printable
|
||||||
|
if( nelKey == NLMISC::KeyF1 || nelKey == NLMISC::KeyF2 ||
|
||||||
|
nelKey == NLMISC::KeyF3 || nelKey == NLMISC::KeyF4 ||
|
||||||
|
nelKey == NLMISC::KeyF5 || nelKey == NLMISC::KeyF6 ||
|
||||||
|
nelKey == NLMISC::KeyF7 || nelKey == NLMISC::KeyF8 ||
|
||||||
|
nelKey == NLMISC::KeyF9 || nelKey == NLMISC::KeyF10 ||
|
||||||
|
nelKey == NLMISC::KeyF11 || nelKey == NLMISC::KeyF12 ||
|
||||||
|
nelKey == NLMISC::KeyF13 || nelKey == NLMISC::KeyF14 ||
|
||||||
|
nelKey == NLMISC::KeyF15 || nelKey == NLMISC::KeyF16 ||
|
||||||
|
nelKey == NLMISC::KeyF17 || nelKey == NLMISC::KeyF18 ||
|
||||||
|
nelKey == NLMISC::KeyF19 || nelKey == NLMISC::KeyF20 ||
|
||||||
|
nelKey == NLMISC::KeyUP || nelKey == NLMISC::KeyDOWN ||
|
||||||
|
nelKey == NLMISC::KeyLEFT || nelKey == NLMISC::KeyRIGHT ||
|
||||||
|
nelKey == NLMISC::KeyHOME || nelKey == NLMISC::KeyEND ||
|
||||||
|
nelKey == NLMISC::KeyPRIOR || nelKey == NLMISC::KeyNEXT ||
|
||||||
|
nelKey == NLMISC::KeyDELETE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// all the fancy wide characters
|
||||||
|
if(character > 127)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void submitEvents(NLMISC::CEventServer& server,
|
void submitEvents(NLMISC::CEventServer& server,
|
||||||
bool allWindows, NLMISC::CCocoaEventEmitter* eventEmitter)
|
bool allWindows, NLMISC::CCocoaEventEmitter* eventEmitter)
|
||||||
{
|
{
|
||||||
|
@ -329,9 +381,6 @@ void submitEvents(NLMISC::CEventServer& server,
|
||||||
float mouseX = event.locationInWindow.x / (float)width;
|
float mouseX = event.locationInWindow.x / (float)width;
|
||||||
float mouseY = event.locationInWindow.y / (float)height;
|
float mouseY = event.locationInWindow.y / (float)height;
|
||||||
|
|
||||||
// string to store symbols in case of key press
|
|
||||||
ucstring ucstr;
|
|
||||||
|
|
||||||
switch(event.type)
|
switch(event.type)
|
||||||
{
|
{
|
||||||
case NSLeftMouseDown:
|
case NSLeftMouseDown:
|
||||||
|
@ -378,15 +427,19 @@ void submitEvents(NLMISC::CEventServer& server,
|
||||||
[event isARepeat] == NO,
|
[event isARepeat] == NO,
|
||||||
eventEmitter));
|
eventEmitter));
|
||||||
|
|
||||||
|
if(isTextKeyEvent(event))
|
||||||
|
{
|
||||||
|
ucstring ucstr;
|
||||||
|
|
||||||
// get the string associated with the key press event
|
// get the string associated with the key press event
|
||||||
ucstr.fromUtf8([[event characters] UTF8String]);
|
ucstr.fromUtf8([[event characters] UTF8String]);
|
||||||
|
|
||||||
// if any, push it to the event server as well
|
// push to event server
|
||||||
if([[event characters] length] > 0)
|
|
||||||
server.postEvent(new NLMISC::CEventChar(
|
server.postEvent(new NLMISC::CEventChar(
|
||||||
ucstr[0],
|
ucstr[0],
|
||||||
NLMISC::noKeyButton,
|
NLMISC::noKeyButton,
|
||||||
eventEmitter));
|
eventEmitter));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case NSKeyUp:
|
case NSKeyUp:
|
||||||
server.postEvent(new NLMISC::CEventKeyUp(
|
server.postEvent(new NLMISC::CEventKeyUp(
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace NLMISC
|
||||||
|
|
||||||
void CCocoaEventEmitter::submitEvents(CEventServer & server, bool allWindows)
|
void CCocoaEventEmitter::submitEvents(CEventServer & server, bool allWindows)
|
||||||
{
|
{
|
||||||
// just forwarding to out cocoa adapter
|
// just forwarding to our cocoa adapter
|
||||||
NL3D::MAC::submitEvents(server, allWindows, this);
|
NL3D::MAC::submitEvents(server, allWindows, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue