2
3
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-13 18:17:49 -04:00

Separate KeyEvents and KeyPresses

This commit is contained in:
2011-08-26 23:17:10 -04:00
parent 6ec190f526
commit e3c65ac817
15 changed files with 32 additions and 293 deletions

View File

@ -52,7 +52,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
plKeyboardDevice* plKeyboardDevice::fInstance = nil;
bool plKeyboardDevice::fKeyboardState[256];
hsBool plKeyboardDevice::fIgnoreCapsLock = false;
hsBool plKeyboardDevice::fKeyIsDeadKey = false;
plKeyboardDevice::plKeyboardDevice() :
fShiftKeyDown(false),
@ -148,7 +147,7 @@ void plKeyboardDevice::Shutdown()
{
}
void plKeyboardDevice::HandleKeyEvent(plOSMsg message, plKeyDef key, bool bKeyDown, hsBool bKeyRepeat)
void plKeyboardDevice::HandleKeyEvent(plOSMsg message, plKeyDef key, bool bKeyDown, hsBool bKeyRepeat, wchar_t c)
{
// update the internal keyboard state
unsigned int keyCode = (unsigned int)key;
@ -177,6 +176,7 @@ void plKeyboardDevice::HandleKeyEvent(plOSMsg message, plKeyDef key, bool bKeyDo
// send a key event...
plKeyEventMsg* pMsg = TRACKED_NEW plKeyEventMsg;
pMsg->SetKeyChar( c );
pMsg->SetKeyCode( key );
pMsg->SetKeyDown( bKeyDown );
pMsg->SetShiftKeyDown( fShiftKeyDown );
@ -199,50 +199,6 @@ void plKeyboardDevice::HandleWindowActivate(bool bActive, HWND hWnd)
}
//// KeyEventToChar //////////////////////////////////////////////////////////
// Translate a Plasma key event to an actual char
wchar_t plKeyboardDevice::KeyEventToChar( plKeyEventMsg *msg )
{
unsigned int code = msg->GetKeyCode();
wchar_t c = 0;
unsigned char kbState[256];
wchar_t buffer[256];
unsigned int scanCode;
int retVal;
buffer[0] = 0;
// 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)
{
// 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;
}
//
//

View File

@ -57,7 +57,7 @@ public:
UInt32 GetFlags() { return fFlags; }
void SetFlags(UInt32 f) { fFlags = f; }
virtual void HandleKeyEvent(plOSMsg message, plKeyDef key, bool bKeyDown, hsBool bKeyRepeat) {;}
virtual void HandleKeyEvent(plOSMsg message, plKeyDef key, bool bKeyDown, hsBool bKeyRepeat, wchar_t c = nil) {;}
virtual void HandleMouseEvent(plOSMsg message, plMouseState state) {;}
virtual void HandleWindowActivate(bool bActive, HWND hWnd) {;}
virtual hsBool MsgReceive(plMessage* msg) {return false;}
@ -79,7 +79,6 @@ class plKeyboardDevice : public plInputDevice
static bool fKeyboardState[256]; // virtual key code is the index, bool is whether it is down or not
static hsBool fIgnoreCapsLock; // set if we want it to ignore this key when translating characters (i.e. for chatting)
static hsBool fKeyIsDeadKey; // the key we just got was a dead key, store the value if you're a text input object
static plKeyboardDevice* fInstance;
void InitKeyboardMaps();
@ -100,19 +99,15 @@ public:
void SetControlMode(int i) { fControlMode = i; }
const char* GetInputName() { return "keyboard"; }
void HandleKeyEvent(plOSMsg message, plKeyDef key, bool bKeyDown, hsBool bKeyRepeat);
void HandleKeyEvent(plOSMsg message, plKeyDef key, bool bKeyDown, hsBool bKeyRepeat, wchar_t c = nil);
virtual void HandleWindowActivate(bool bActive, HWND hWnd);
virtual hsBool IsCapsLockKeyOn();
virtual void Shutdown();
static hsBool IgnoreCapsLock() { return fIgnoreCapsLock; }
static void IgnoreCapsLock(hsBool ignore) { fIgnoreCapsLock = ignore; }
static hsBool KeyIsDeadKey() { return fKeyIsDeadKey; }
static plKeyboardDevice* GetInstance() { return fInstance; }
static wchar_t KeyEventToChar( plKeyEventMsg *msg );
};
class plPlate;

View File

@ -132,6 +132,8 @@ hsBool plInputInterface::ProcessKeyBindings( plInputEventMsg *msg )
plKeyEventMsg *keyMsg = plKeyEventMsg::ConvertNoRef( msg );
if( keyMsg == nil )
return false;
if ( keyMsg->GetKeyChar())
return false;
/// We might have controls that are currently enabled that are triggered in part by

View File

@ -273,6 +273,21 @@ void plInputManager::HandleWin32ControlEvent(UINT message, WPARAM Wparam, LPARAM
fInputDevices[i]->HandleKeyEvent( KEYUP, UntranslateKey((plKeyDef)Wparam, bExtended), false, false );
}
break;
case CHAR_MSG:
{
// These are handled by KEYUP/KEYDOWN and should not be sent
// We don't like garbage getting in string fields
if (Wparam == KEY_BACKSPACE || Wparam == 0x0A || Wparam == KEY_ESCAPE ||
Wparam == KEY_TAB || Wparam == 0x0D)
break;
bExtended = Lparam >> 24 & 1;
hsBool bRepeat = ((Lparam >> 29) & 0xf) != 0;
bool down = !(Lparam >> 31);
for (int i=0; i<fInputDevices.Count(); i++)
fInputDevices[i]->HandleKeyEvent( CHAR_MSG, (plKeyDef)-1, down, bRepeat, (wchar_t)Wparam );
}
break;
case MOUSEWHEEL:
{
plMouseEventMsg* pMsg = TRACKED_NEW plMouseEventMsg;