diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp index 6f076168..1bd0c886 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp @@ -519,7 +519,8 @@ hsBool pfConsole::MsgReceive( plMessage *msg ) void pfConsole::IHandleKey( plKeyEventMsg *msg ) { - char *c, key; + char *c; + wchar_t key; int i,eol; static hsBool findAgain = false; static UInt32 findCounter = 0; @@ -831,13 +832,13 @@ void pfConsole::IHandleKey( plKeyEventMsg *msg ) { key = plKeyboardDevice::KeyEventToChar( msg ); // do they want to go into help mode? - if( !fPythonMode && key == '?' && fWorkingCursor == 0 ) + if( !fPythonMode && key == L'?' && fWorkingCursor == 0 ) { /// Go into help mode fHelpMode = true; } // do they want to go into Python mode? - else if( !fHelpMode && key == '\\' && fWorkingCursor == 0 ) + else if( !fHelpMode && key == L'\\' && fWorkingCursor == 0 ) { // toggle Python mode fPythonMode = fPythonMode ? false:true; diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp index c394e640..69129450 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp @@ -879,7 +879,7 @@ void pfGUIControlMod::Write( hsStream *s, hsResMgr *mgr ) //// HandleKeyPress/Event //////////////////////////////////////////////////// -hsBool pfGUIControlMod::HandleKeyPress( char key, UInt8 modifiers ) +hsBool pfGUIControlMod::HandleKeyPress( wchar_t key, UInt8 modifiers ) { return false; } diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.h b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.h index bb1112b8..568413a3 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.h +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.h @@ -193,7 +193,7 @@ class pfGUIControlMod : public plSingleModifier virtual void HandleMouseHover( hsPoint3 &mousePt, UInt8 modifiers ) {;} virtual void HandleMouseDblClick( hsPoint3 &mousePt, UInt8 modifiers ) {;} - virtual hsBool HandleKeyPress( char key, UInt8 modifiers ); + virtual hsBool HandleKeyPress( wchar_t key, UInt8 modifiers ); virtual hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers ); void SetHandler( pfGUICtrlProcObject *h ) { ISetHandler( h, true ); } diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIDialogMod.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIDialogMod.cpp index c3935cdc..cd23b9ce 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIDialogMod.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIDialogMod.cpp @@ -551,7 +551,7 @@ hsBool pfGUIDialogMod::HandleKeyEvent( pfGameGUIMgr::EventType event, plKey //// HandleKeyPress ////////////////////////////////////////////////////////// -hsBool pfGUIDialogMod::HandleKeyPress( char key, UInt8 modifiers ) +hsBool pfGUIDialogMod::HandleKeyPress( wchar_t key, UInt8 modifiers ) { // Same deal as HandleKeyPress. Only problem is, we needed the msg to translate // to a char, so it had to be done up at the mgr level (sadly) diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIDialogMod.h b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIDialogMod.h index 84c1eb6e..19251b12 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIDialogMod.h +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIDialogMod.h @@ -119,7 +119,7 @@ class pfGUIDialogMod : public plSingleModifier virtual hsBool HandleMouseEvent( pfGameGUIMgr::EventType event, hsScalar mouseX, hsScalar mouseY, UInt8 modifiers ); hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers ); - hsBool HandleKeyPress( char key, UInt8 modifiers ); + hsBool HandleKeyPress( wchar_t key, UInt8 modifiers ); void UpdateInterestingThings( hsScalar mouseX, hsScalar mouseY, UInt8 modifiers, hsBool modalPreset ); void SetControlOfInterest( pfGUIControlMod *c ); diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.cpp index cff202c3..210c6ec4 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.cpp @@ -277,10 +277,8 @@ void pfGUIEditBoxMod::HandleMouseDrag( hsPoint3 &mousePt, UInt8 modifiers ) { } -hsBool pfGUIEditBoxMod::HandleKeyPress( char inKey, UInt8 modifiers ) +hsBool pfGUIEditBoxMod::HandleKeyPress( wchar_t key, UInt8 modifiers ) { - wchar_t key = (wchar_t)inKey; - if( fBuffer == nil ) return false; diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.h b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.h index 886361cd..36cde270 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.h +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.h @@ -90,7 +90,7 @@ class pfGUIEditBoxMod : public pfGUIControlMod virtual void HandleMouseUp( hsPoint3 &mousePt, UInt8 modifiers ); virtual void HandleMouseDrag( hsPoint3 &mousePt, UInt8 modifiers ); - virtual hsBool HandleKeyPress( char key, UInt8 modifiers ); + virtual hsBool HandleKeyPress( wchar_t key, UInt8 modifiers ); virtual hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers ); virtual void PurgeDynaTextMapImage(); diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp index c9824920..8efb315a 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp @@ -905,7 +905,7 @@ void pfGUIListBoxMod::AddSelection( Int32 item ) //// HandleKeyPress ////////////////////////////////////////////////////////// -hsBool pfGUIListBoxMod::HandleKeyPress( char key, UInt8 modifiers ) +hsBool pfGUIListBoxMod::HandleKeyPress( wchar_t key, UInt8 modifiers ) { return false; } diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.h b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.h index 6c56dc45..c6416e34 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.h +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.h @@ -133,7 +133,7 @@ class pfGUIListBoxMod : public pfGUIControlMod virtual void HandleMouseHover( hsPoint3 &mousePt, UInt8 modifiers ); virtual void HandleMouseDblClick( hsPoint3 &mousePt, UInt8 modifiers ); - virtual hsBool HandleKeyPress( char key, UInt8 modifiers ); + virtual hsBool HandleKeyPress( wchar_t key, UInt8 modifiers ); virtual hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers ); virtual hsBool FilterMousePosition( hsPoint3 &mousePt ); diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp index c2d73bc0..af3233a8 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp @@ -1072,10 +1072,8 @@ void pfGUIMultiLineEditCtrl::HandleMouseDrag( hsPoint3 &mousePt, UInt8 modifi IMoveCursorTo( IPointToPosition( (Int16)(mousePt.fX), (Int16)(mousePt.fY) ) ); } -hsBool pfGUIMultiLineEditCtrl::HandleKeyPress( char keyIn, UInt8 modifiers ) +hsBool pfGUIMultiLineEditCtrl::HandleKeyPress( wchar_t key, UInt8 modifiers ) { - wchar_t key = (wchar_t)keyIn; - if ((fPrevCtrl || fNextCtrl) && (fLineStarts.GetCount() <= GetFirstVisibleLine())) return true; // we're ignoring if we can't actually edit our visible frame (and we're linked) diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h index 8239b654..24bd9272 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h @@ -195,7 +195,7 @@ class pfGUIMultiLineEditCtrl : public pfGUIControlMod virtual void HandleMouseUp( hsPoint3 &mousePt, UInt8 modifiers ); virtual void HandleMouseDrag( hsPoint3 &mousePt, UInt8 modifiers ); - virtual hsBool HandleKeyPress( char key, UInt8 modifiers ); + virtual hsBool HandleKeyPress( wchar_t key, UInt8 modifiers ); virtual hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers ); virtual void PurgeDynaTextMapImage(); diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.cpp index f1a21773..bacca86c 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.cpp @@ -594,10 +594,13 @@ hsBool pfGameGUIMgr::IHandleKeyEvt( EventType event, plKeyDef key, UInt8 modifi // Like IHandleKeyPress, but takes in a char for distributing actual // characters typed. -hsBool pfGameGUIMgr::IHandleKeyPress( char key, UInt8 modifiers ) +hsBool pfGameGUIMgr::IHandleKeyPress( wchar_t key, UInt8 modifiers ) { pfGUIDialogMod *dlg; + // Really... Don't handle any nil keypresses + if (key == nil) + return false; for( dlg = fActiveDialogs; dlg != nil; dlg = dlg->GetNext() ) { diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.h b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.h index f6f10b91..5ae7c093 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.h +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.h @@ -153,7 +153,7 @@ class pfGameGUIMgr : public hsKeyedObject hsBool IHandleMouse( EventType event, hsScalar mouseX, hsScalar mouseY, UInt8 modifiers, UInt32 *desiredCursor ); hsBool IHandleKeyEvt( EventType event, plKeyDef key, UInt8 modifiers ); - hsBool IHandleKeyPress( char key, UInt8 modifiers ); + hsBool IHandleKeyPress( wchar_t key, UInt8 modifiers ); hsBool IModalBlocking( void ); diff --git a/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp b/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp index bfd28138..41c89652 100644 --- a/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp @@ -890,7 +890,7 @@ void plPythonFileMod::RemoveTarget(plSceneObject* so) void plPythonFileMod::HandleDiscardedKey( plKeyEventMsg *msg ) { // So OnDefaultKeyCaught takes two parameters: the key character pressed and a boolean saying up or down - char keyChar = plKeyboardDevice::KeyEventToChar( msg ); + wchar_t keyChar = plKeyboardDevice::KeyEventToChar( msg ); // if the caps lock is down then reverse upper and lowercase if ( msg->GetCapsLockKeyDown() ) diff --git a/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp b/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp index d01d7093..10533e6f 100644 --- a/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp +++ b/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp @@ -204,120 +204,43 @@ void plKeyboardDevice::HandleWindowActivate(bool bActive, HWND hWnd) //// KeyEventToChar ////////////////////////////////////////////////////////// // Translate a Plasma key event to an actual char -char plKeyboardDevice::KeyEventToChar( plKeyEventMsg *msg ) +wchar_t plKeyboardDevice::KeyEventToChar( plKeyEventMsg *msg ) { - short code = msg->GetKeyCode(); - char c = 0; + unsigned int code = msg->GetKeyCode(); + wchar_t c = 0; unsigned char kbState[256]; - unsigned char buffer[256]; - UINT scanCode; + wchar_t buffer[256]; + unsigned int scanCode; int retVal; buffer[0] = 0; - switch( code ) + // let windows translate everything for us! + scanCode = MapVirtualKeyW(code, 0); + GetKeyboardState(kbState); + if (fIgnoreCapsLock) + kbState[KEY_CAPSLOCK] = 0; // clear the caps lock key + retVal = ToUnicode(code, scanCode, kbState, (wchar_t*)buffer, 256, 0); + if (retVal == -1) { - case KEY_A: - case KEY_B: - case KEY_C: - case KEY_D: - case KEY_E: - case KEY_F: - case KEY_G: - case KEY_H: - case KEY_I: - case KEY_J: - case KEY_K: - case KEY_L: - case KEY_M: - case KEY_N: - case KEY_O: - case KEY_P: - case KEY_Q: - case KEY_R: - case KEY_S: - case KEY_T: - case KEY_U: - case KEY_V: - case KEY_W: - case KEY_X: - case KEY_Y: - case KEY_Z: - case KEY_1: - case KEY_2: - case KEY_3: - case KEY_4: - case KEY_5: - case KEY_6: - case KEY_7: - case KEY_8: - case KEY_9: - case KEY_0: - case KEY_TILDE: - case KEY_COMMA: - case KEY_PERIOD: - case KEY_LBRACKET: - case KEY_RBRACKET: - case KEY_BACKSLASH: - case KEY_SLASH: - case KEY_DASH: - case KEY_EQUAL: - case KEY_SEMICOLON: - case KEY_QUOTE: - // let windows translate everything for us! - scanCode = MapVirtualKeyEx(code,0,GetKeyboardLayout(0)); - GetKeyboardState(kbState); - if (fIgnoreCapsLock) - kbState[KEY_CAPSLOCK] = 0; // clear the caps lock key - retVal = ToAsciiEx(code,scanCode,kbState,(unsigned short*)buffer,0,GetKeyboardLayout(0)); - if (retVal == 2) - { - if ((buffer[0] == buffer[1]) && (!fKeyIsDeadKey)) - { - // it's actually a dead key, since the previous key wasn't a dead key - c = (char)buffer[0]; - fKeyIsDeadKey = true; - } - else - { - c = (char)buffer[1]; // it was an untranslated dead key, so copy the unconverted key - fKeyIsDeadKey = false; - } - } - else if (retVal == 0) - c = 0; // it's invalid - else - { - c = (char)buffer[0]; - if (retVal < 0) // the key was a dead key - fKeyIsDeadKey = true; - else - fKeyIsDeadKey = false; - } - break; - - case KEY_ESCAPE: c = 27; break; - case KEY_TAB: c = '\t'; break; - case KEY_BACKSPACE: c = 8; break; - case KEY_ENTER: c = '\n'; break; - case KEY_SPACE: c = ' '; break; - - // numlock on numbers - case KEY_NUMPAD0: c = '0'; break; - case KEY_NUMPAD1: c = '1'; break; - case KEY_NUMPAD2: c = '2'; break; - case KEY_NUMPAD3: c = '3'; break; - case KEY_NUMPAD4: c = '4'; break; - case KEY_NUMPAD5: c = '5'; break; - case KEY_NUMPAD6: c = '6'; break; - case KEY_NUMPAD7: c = '7'; break; - case KEY_NUMPAD8: c = '8'; break; - case KEY_NUMPAD9: c = '9'; break; - - // everything else - default: - c = 0; - break; + // It's a stored dead key. + c = 0; + fKeyIsDeadKey = true; + } + else if (retVal == 0) + // Invalid crap + c = 0; + else if (retVal == 1) + { + // Exactly one good character + fKeyIsDeadKey = false; + c = buffer[0]; + } + else if (retVal >= 2) + { + fKeyIsDeadKey = !fKeyIsDeadKey; + if (!fKeyIsDeadKey) + c = buffer[0]; } return c; diff --git a/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.h b/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.h index c694a84d..3451ce7b 100644 --- a/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.h +++ b/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.h @@ -113,7 +113,7 @@ public: static plKeyboardDevice* GetInstance() { return fInstance; } - static char KeyEventToChar( plKeyEventMsg *msg ); + static wchar_t KeyEventToChar( plKeyEventMsg *msg ); }; class plPlate;