2003-11-14 17:48:57 +01:00
|
|
|
/*
|
|
|
|
*Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
*Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
*"Software"), to deal in the Software without restriction, including
|
|
|
|
*without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
*distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
*permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
*the following conditions:
|
|
|
|
*
|
|
|
|
*The above copyright notice and this permission notice shall be
|
|
|
|
*included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
*EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
*MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
*NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
|
|
|
|
*ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
|
|
*CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
*WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*Except as contained in this notice, the name of the XFree86 Project
|
|
|
|
*shall not be used in advertising or otherwise to promote the sale, use
|
|
|
|
*or other dealings in this Software without prior written authorization
|
|
|
|
*from the XFree86 Project.
|
|
|
|
*
|
|
|
|
* Authors: Dakshinamurthy Karra
|
|
|
|
* Suhaib M Siddiqi
|
|
|
|
* Peter Busch
|
|
|
|
* Harold L Hunt II
|
|
|
|
*/
|
|
|
|
|
2005-07-05 00:10:43 +02:00
|
|
|
#ifdef HAVE_XWIN_CONFIG_H
|
|
|
|
#include <xwin-config.h>
|
|
|
|
#endif
|
2003-11-14 17:48:57 +01:00
|
|
|
#include "win.h"
|
|
|
|
#include "winkeybd.h"
|
|
|
|
#include "winconfig.h"
|
2004-06-21 15:19:32 +02:00
|
|
|
#include "winmsg.h"
|
|
|
|
|
2008-03-18 09:05:57 +01:00
|
|
|
#include "xkbsrv.h"
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2012-11-05 15:54:51 +01:00
|
|
|
/* C does not have a logical XOR operator, so we use a macro instead */
|
|
|
|
#define LOGICAL_XOR(a,b) ((!(a) && (b)) || ((a) && !(b)))
|
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
static Bool g_winKeyState[NUM_KEYCODES];
|
|
|
|
|
2004-06-21 15:19:32 +02:00
|
|
|
/*
|
|
|
|
* Local prototypes
|
|
|
|
*/
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2004-06-21 15:19:32 +02:00
|
|
|
static void
|
2012-03-21 20:55:09 +01:00
|
|
|
winKeybdBell(int iPercent, DeviceIntPtr pDeviceInt, pointer pCtrl, int iClass);
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2004-06-21 15:19:32 +02:00
|
|
|
static void
|
2012-03-21 20:55:09 +01:00
|
|
|
winKeybdCtrl(DeviceIntPtr pDevice, KeybdCtrl * pCtrl);
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Translate a Windows WM_[SYS]KEY(UP/DOWN) message
|
|
|
|
* into an ASCII scan code.
|
|
|
|
*
|
|
|
|
* We do this ourselves, rather than letting Windows handle it,
|
|
|
|
* because Windows tends to munge the handling of special keys,
|
|
|
|
* like AltGr on European keyboards.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
winTranslateKey(WPARAM wParam, LPARAM lParam, int *piScanCode)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
int iKeyFixup = g_iKeyMap[wParam * WIN_KEYMAP_COLS + 1];
|
|
|
|
int iKeyFixupEx = g_iKeyMap[wParam * WIN_KEYMAP_COLS + 2];
|
|
|
|
int iParam = HIWORD(lParam);
|
|
|
|
int iParamScanCode = LOBYTE(iParam);
|
2009-11-01 19:18:45 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
winDebug("winTranslateKey: wParam %08x lParam %08x\n", wParam, lParam);
|
2010-04-14 22:45:29 +02:00
|
|
|
|
2009-11-01 19:18:45 +01:00
|
|
|
/* WM_ key messages faked by Vista speech recognition (WSR) don't have a
|
|
|
|
* scan code.
|
|
|
|
*
|
|
|
|
* Vocola 3 (Rick Mohr's supplement to WSR) uses
|
|
|
|
* System.Windows.Forms.SendKeys.SendWait(), which appears always to give a
|
|
|
|
* scan code of 1
|
|
|
|
*/
|
2012-03-21 20:55:09 +01:00
|
|
|
if (iParamScanCode <= 1) {
|
|
|
|
if (VK_PRIOR <= wParam && wParam <= VK_DOWN)
|
|
|
|
/* Trigger special case table to translate to extended
|
|
|
|
* keycode, otherwise if num_lock is on, we can get keypad
|
|
|
|
* numbers instead of navigation keys. */
|
|
|
|
iParam |= KF_EXTENDED;
|
|
|
|
else
|
|
|
|
iParamScanCode = MapVirtualKeyEx(wParam,
|
|
|
|
/*MAPVK_VK_TO_VSC */ 0,
|
|
|
|
GetKeyboardLayout(0));
|
2009-11-01 19:18:45 +01:00
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
/* Branch on special extended, special non-extended, or normal key */
|
|
|
|
if ((iParam & KF_EXTENDED) && iKeyFixupEx)
|
|
|
|
*piScanCode = iKeyFixupEx;
|
|
|
|
else if (iKeyFixup)
|
|
|
|
*piScanCode = iKeyFixup;
|
|
|
|
else if (wParam == 0 && iParamScanCode == 0x70)
|
2005-02-08 16:20:01 +01:00
|
|
|
*piScanCode = KEY_HKTG;
|
2012-03-21 20:55:09 +01:00
|
|
|
else
|
|
|
|
switch (iParamScanCode) {
|
|
|
|
case 0x70:
|
|
|
|
*piScanCode = KEY_HKTG;
|
|
|
|
break;
|
|
|
|
case 0x73:
|
|
|
|
*piScanCode = KEY_BSlash2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*piScanCode = iParamScanCode;
|
|
|
|
break;
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Ring the keyboard bell (system speaker on PCs) */
|
2004-06-21 15:19:32 +02:00
|
|
|
static void
|
2012-03-21 20:55:09 +01:00
|
|
|
winKeybdBell(int iPercent, DeviceIntPtr pDeviceInt, pointer pCtrl, int iClass)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
/*
|
|
|
|
* We can't use Beep () here because it uses the PC speaker
|
|
|
|
* on NT/2000. MessageBeep (MB_OK) will play the default system
|
|
|
|
* sound on systems with a sound card or it will beep the PC speaker
|
|
|
|
* on systems that do not have a sound card.
|
|
|
|
*/
|
|
|
|
MessageBeep(MB_OK);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Change some keyboard configuration parameters */
|
2004-06-21 15:19:32 +02:00
|
|
|
static void
|
2012-03-21 20:55:09 +01:00
|
|
|
winKeybdCtrl(DeviceIntPtr pDevice, KeybdCtrl * pCtrl)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See Porting Layer Definition - p. 18
|
|
|
|
* winKeybdProc is known as a DeviceProc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
winKeybdProc(DeviceIntPtr pDeviceInt, int iState)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
DevicePtr pDevice = (DevicePtr) pDeviceInt;
|
|
|
|
XkbSrvInfoPtr xkbi;
|
|
|
|
XkbControlsPtr ctrl;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
switch (iState) {
|
2003-11-14 17:48:57 +01:00
|
|
|
case DEVICE_INIT:
|
2012-03-21 20:55:09 +01:00
|
|
|
winConfigKeyboard(pDeviceInt);
|
|
|
|
|
|
|
|
/* FIXME: Maybe we should use winGetKbdLeds () here? */
|
|
|
|
defaultKeyboardControl.leds = g_winInfo.keyboard.leds;
|
|
|
|
|
|
|
|
winErrorFVerb(2, "Rules = \"%s\" Model = \"%s\" Layout = \"%s\""
|
|
|
|
" Variant = \"%s\" Options = \"%s\"\n",
|
|
|
|
g_winInfo.xkb.rules ? g_winInfo.xkb.rules : "none",
|
|
|
|
g_winInfo.xkb.model ? g_winInfo.xkb.model : "none",
|
|
|
|
g_winInfo.xkb.layout ? g_winInfo.xkb.layout : "none",
|
|
|
|
g_winInfo.xkb.variant ? g_winInfo.xkb.variant : "none",
|
|
|
|
g_winInfo.xkb.options ? g_winInfo.xkb.options : "none");
|
|
|
|
|
|
|
|
InitKeyboardDeviceStruct(pDeviceInt,
|
|
|
|
&g_winInfo.xkb, winKeybdBell, winKeybdCtrl);
|
|
|
|
|
|
|
|
xkbi = pDeviceInt->key->xkbInfo;
|
|
|
|
if ((xkbi != NULL) && (xkbi->desc != NULL)) {
|
|
|
|
ctrl = xkbi->desc->ctrls;
|
|
|
|
ctrl->repeat_delay = g_winInfo.keyboard.delay;
|
|
|
|
ctrl->repeat_interval = 1000 / g_winInfo.keyboard.rate;
|
2009-01-26 14:15:07 +01:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
else {
|
|
|
|
winErrorFVerb(1,
|
|
|
|
"winKeybdProc - Error initializing keyboard AutoRepeat\n");
|
2004-06-21 15:19:32 +02:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
break;
|
2009-06-19 22:14:47 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
case DEVICE_ON:
|
|
|
|
pDevice->on = TRUE;
|
|
|
|
|
|
|
|
// immediately copy the state of this keyboard device to the VCK
|
|
|
|
// (which otherwise happens lazily after the first keypress)
|
|
|
|
CopyKeyClass(pDeviceInt, inputInfo.keyboard);
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
case DEVICE_CLOSE:
|
2012-03-21 20:55:09 +01:00
|
|
|
case DEVICE_OFF:
|
|
|
|
pDevice->on = FALSE;
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
return Success;
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Detect current mode key states upon server startup.
|
|
|
|
*
|
|
|
|
* Simulate a press and release of any key that is currently
|
|
|
|
* toggled.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
winInitializeModeKeyStates(void)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
/* Restore NumLock */
|
|
|
|
if (GetKeyState(VK_NUMLOCK) & 0x0001) {
|
|
|
|
winSendKeyEvent(KEY_NumLock, TRUE);
|
|
|
|
winSendKeyEvent(KEY_NumLock, FALSE);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
/* Restore CapsLock */
|
|
|
|
if (GetKeyState(VK_CAPITAL) & 0x0001) {
|
|
|
|
winSendKeyEvent(KEY_CapsLock, TRUE);
|
|
|
|
winSendKeyEvent(KEY_CapsLock, FALSE);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
/* Restore ScrollLock */
|
|
|
|
if (GetKeyState(VK_SCROLL) & 0x0001) {
|
|
|
|
winSendKeyEvent(KEY_ScrollLock, TRUE);
|
|
|
|
winSendKeyEvent(KEY_ScrollLock, FALSE);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
/* Restore KanaLock */
|
|
|
|
if (GetKeyState(VK_KANA) & 0x0001) {
|
|
|
|
winSendKeyEvent(KEY_HKTG, TRUE);
|
|
|
|
winSendKeyEvent(KEY_HKTG, FALSE);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Upon regaining the keyboard focus we must
|
|
|
|
* resynchronize our internal mode key states
|
|
|
|
* with the actual state of the keys.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
winRestoreModeKeyStates(void)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
DWORD dwKeyState;
|
|
|
|
BOOL processEvents = TRUE;
|
|
|
|
unsigned short internalKeyStates;
|
|
|
|
|
|
|
|
/* X server is being initialized */
|
|
|
|
if (!inputInfo.keyboard)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Only process events if the rootwindow is mapped. The keyboard events
|
|
|
|
* will cause segfaults otherwise */
|
|
|
|
if (screenInfo.screens[0]->root &&
|
|
|
|
screenInfo.screens[0]->root->mapped == FALSE)
|
|
|
|
processEvents = FALSE;
|
|
|
|
|
|
|
|
/* Force to process all pending events in the mi event queue */
|
|
|
|
if (processEvents)
|
|
|
|
mieqProcessInputEvents();
|
|
|
|
|
|
|
|
/* Read the mode key states of our X server */
|
|
|
|
/* (stored in the virtual core keyboard) */
|
|
|
|
internalKeyStates =
|
|
|
|
XkbStateFieldFromRec(&inputInfo.keyboard->key->xkbInfo->state);
|
|
|
|
winDebug("winRestoreModeKeyStates: state %d\n", internalKeyStates);
|
|
|
|
|
|
|
|
|
2012-11-05 15:54:51 +01:00
|
|
|
/*
|
|
|
|
Check if latching modifier key states have changed, and if so,
|
|
|
|
fake a press and a release to toggle the modifier to the correct
|
|
|
|
state
|
|
|
|
*/
|
2012-03-21 20:55:09 +01:00
|
|
|
dwKeyState = GetKeyState(VK_NUMLOCK) & 0x0001;
|
2012-11-05 15:54:51 +01:00
|
|
|
if (LOGICAL_XOR(internalKeyStates & NumLockMask, dwKeyState)) {
|
2012-03-21 20:55:09 +01:00
|
|
|
winSendKeyEvent(KEY_NumLock, TRUE);
|
|
|
|
winSendKeyEvent(KEY_NumLock, FALSE);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
dwKeyState = GetKeyState(VK_CAPITAL) & 0x0001;
|
2012-11-05 15:54:51 +01:00
|
|
|
if (LOGICAL_XOR(internalKeyStates & LockMask, dwKeyState)) {
|
2012-03-21 20:55:09 +01:00
|
|
|
winSendKeyEvent(KEY_CapsLock, TRUE);
|
|
|
|
winSendKeyEvent(KEY_CapsLock, FALSE);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
dwKeyState = GetKeyState(VK_SCROLL) & 0x0001;
|
2012-11-05 15:54:51 +01:00
|
|
|
if (LOGICAL_XOR(internalKeyStates & ScrollLockMask, dwKeyState)) {
|
2012-03-21 20:55:09 +01:00
|
|
|
winSendKeyEvent(KEY_ScrollLock, TRUE);
|
|
|
|
winSendKeyEvent(KEY_ScrollLock, FALSE);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
dwKeyState = GetKeyState(VK_KANA) & 0x0001;
|
2012-11-05 15:54:51 +01:00
|
|
|
if (LOGICAL_XOR(internalKeyStates & KanaMask, dwKeyState)) {
|
2012-03-21 20:55:09 +01:00
|
|
|
winSendKeyEvent(KEY_HKTG, TRUE);
|
|
|
|
winSendKeyEvent(KEY_HKTG, FALSE);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for the lovely fake Control_L press/release generated by Windows
|
|
|
|
* when AltGr is pressed/released on a non-U.S. keyboard.
|
|
|
|
*/
|
|
|
|
|
|
|
|
Bool
|
2012-03-21 20:55:09 +01:00
|
|
|
winIsFakeCtrl_L(UINT message, WPARAM wParam, LPARAM lParam)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
MSG msgNext;
|
|
|
|
LONG lTime;
|
|
|
|
Bool fReturn;
|
|
|
|
|
|
|
|
static Bool lastWasControlL = FALSE;
|
|
|
|
static UINT lastMessage;
|
|
|
|
static LONG lastTime;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fake Ctrl_L presses will be followed by an Alt_R press
|
|
|
|
* with the same timestamp as the Ctrl_L press.
|
|
|
|
*/
|
|
|
|
if ((message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
|
|
|
|
&& wParam == VK_CONTROL && (HIWORD(lParam) & KF_EXTENDED) == 0) {
|
|
|
|
/* Got a Ctrl_L press */
|
|
|
|
|
|
|
|
/* Get time of current message */
|
|
|
|
lTime = GetMessageTime();
|
|
|
|
|
|
|
|
/* Look for next press message */
|
|
|
|
fReturn = PeekMessage(&msgNext, NULL,
|
|
|
|
WM_KEYDOWN, WM_SYSKEYDOWN, PM_NOREMOVE);
|
|
|
|
|
|
|
|
if (fReturn && msgNext.message != WM_KEYDOWN &&
|
|
|
|
msgNext.message != WM_SYSKEYDOWN)
|
|
|
|
fReturn = 0;
|
|
|
|
|
|
|
|
if (!fReturn) {
|
|
|
|
lastWasControlL = TRUE;
|
|
|
|
lastMessage = message;
|
|
|
|
lastTime = lTime;
|
2011-09-05 14:32:01 +02:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
else {
|
|
|
|
lastWasControlL = FALSE;
|
2011-09-05 14:32:01 +02:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
/* Is next press an Alt_R with the same timestamp? */
|
|
|
|
if (fReturn && msgNext.wParam == VK_MENU
|
|
|
|
&& msgNext.time == lTime
|
|
|
|
&& (HIWORD(msgNext.lParam) & KF_EXTENDED)) {
|
|
|
|
/*
|
|
|
|
* Next key press is Alt_R with same timestamp as current
|
|
|
|
* Ctrl_L message. Therefore, this Ctrl_L press is a fake
|
|
|
|
* event, so discard it.
|
|
|
|
*/
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
/*
|
|
|
|
* Sometimes, the Alt_R press message is not yet posted when the
|
|
|
|
* fake Ctrl_L press message arrives (even though it has the
|
|
|
|
* same timestamp), so check for an Alt_R press message that has
|
|
|
|
* arrived since the last Ctrl_L message.
|
|
|
|
*/
|
|
|
|
else if ((message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
|
|
|
|
&& wParam == VK_MENU && (HIWORD(lParam) & KF_EXTENDED)) {
|
|
|
|
/* Got a Alt_R press */
|
|
|
|
|
|
|
|
if (lastWasControlL) {
|
|
|
|
lTime = GetMessageTime();
|
|
|
|
|
|
|
|
if (lastTime == lTime) {
|
2011-09-05 14:32:01 +02:00
|
|
|
/* Undo the fake Ctrl_L press by sending a fake Ctrl_L release */
|
2012-03-21 20:55:09 +01:00
|
|
|
winSendKeyEvent(KEY_LCtrl, FALSE);
|
2011-09-05 14:32:01 +02:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
lastWasControlL = FALSE;
|
2011-09-05 14:32:01 +02:00
|
|
|
}
|
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
/*
|
|
|
|
* Fake Ctrl_L releases will be followed by an Alt_R release
|
|
|
|
* with the same timestamp as the Ctrl_L release.
|
|
|
|
*/
|
|
|
|
else if ((message == WM_KEYUP || message == WM_SYSKEYUP)
|
|
|
|
&& wParam == VK_CONTROL && (HIWORD(lParam) & KF_EXTENDED) == 0) {
|
|
|
|
/* Got a Ctrl_L release */
|
|
|
|
|
|
|
|
/* Get time of current message */
|
|
|
|
lTime = GetMessageTime();
|
|
|
|
|
|
|
|
/* Look for next release message */
|
|
|
|
fReturn = PeekMessage(&msgNext, NULL,
|
|
|
|
WM_KEYUP, WM_SYSKEYUP, PM_NOREMOVE);
|
|
|
|
|
|
|
|
if (fReturn && msgNext.message != WM_KEYUP &&
|
|
|
|
msgNext.message != WM_SYSKEYUP)
|
|
|
|
fReturn = 0;
|
|
|
|
|
|
|
|
lastWasControlL = FALSE;
|
|
|
|
|
|
|
|
/* Is next press an Alt_R with the same timestamp? */
|
|
|
|
if (fReturn
|
|
|
|
&& (msgNext.message == WM_KEYUP || msgNext.message == WM_SYSKEYUP)
|
|
|
|
&& msgNext.wParam == VK_MENU
|
|
|
|
&& msgNext.time == lTime
|
|
|
|
&& (HIWORD(msgNext.lParam) & KF_EXTENDED)) {
|
|
|
|
/*
|
|
|
|
* Next key release is Alt_R with same timestamp as current
|
|
|
|
* Ctrl_L message. Therefore, this Ctrl_L release is a fake
|
|
|
|
* event, so discard it.
|
|
|
|
*/
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
else {
|
|
|
|
/* On any other press or release message, we don't have a
|
|
|
|
potentially fake Ctrl_L to worry about anymore... */
|
|
|
|
lastWasControlL = FALSE;
|
2011-09-05 14:32:01 +02:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
/* Not a fake control left press/release */
|
|
|
|
return FALSE;
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lift any modifier keys that are pressed
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
winKeybdReleaseKeys(void)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
int i;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2004-11-15 16:06:51 +01:00
|
|
|
#ifdef HAS_DEVWINDOWS
|
2012-03-21 20:55:09 +01:00
|
|
|
/* Verify that the mi input system has been initialized */
|
|
|
|
if (g_fdMessageQueue == WIN_FD_INVALID)
|
|
|
|
return;
|
2004-11-15 16:06:51 +01:00
|
|
|
#endif
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
/* Loop through all keys */
|
|
|
|
for (i = 0; i < NUM_KEYCODES; ++i) {
|
|
|
|
/* Pop key if pressed */
|
|
|
|
if (g_winKeyState[i])
|
|
|
|
winSendKeyEvent(i, FALSE);
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
/* Reset pressed flag for keys */
|
|
|
|
g_winKeyState[i] = FALSE;
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take a raw X key code and send an up or down event for it.
|
|
|
|
*
|
|
|
|
* Thanks to VNC for inspiration, though it is a simple function.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
winSendKeyEvent(DWORD dwKey, Bool fDown)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
/*
|
|
|
|
* When alt-tabing between screens we can get phantom key up messages
|
|
|
|
* Here we only pass them through it we think we should!
|
|
|
|
*/
|
|
|
|
if (g_winKeyState[dwKey] == FALSE && fDown == FALSE)
|
|
|
|
return;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
/* Update the keyState map */
|
|
|
|
g_winKeyState[dwKey] = fDown;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
QueueKeyboardEvents(g_pwinKeyboard, fDown ? KeyPress : KeyRelease,
|
|
|
|
dwKey + MIN_KEYCODE, NULL);
|
2008-11-02 19:27:12 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
winDebug("winSendKeyEvent: dwKey: %d, fDown: %d\n", dwKey, fDown);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
2005-07-05 19:52:35 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
BOOL
|
|
|
|
winCheckKeyPressed(WPARAM wParam, LPARAM lParam)
|
2005-07-05 19:52:35 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
switch (wParam) {
|
2005-07-05 19:52:35 +02:00
|
|
|
case VK_CONTROL:
|
2012-03-21 20:55:09 +01:00
|
|
|
if ((lParam & 0x1ff0000) == 0x11d0000 && g_winKeyState[KEY_RCtrl])
|
|
|
|
return TRUE;
|
|
|
|
if ((lParam & 0x1ff0000) == 0x01d0000 && g_winKeyState[KEY_LCtrl])
|
|
|
|
return TRUE;
|
|
|
|
break;
|
2005-07-05 19:52:35 +02:00
|
|
|
case VK_SHIFT:
|
2012-03-21 20:55:09 +01:00
|
|
|
if ((lParam & 0x1ff0000) == 0x0360000 && g_winKeyState[KEY_ShiftR])
|
|
|
|
return TRUE;
|
|
|
|
if ((lParam & 0x1ff0000) == 0x02a0000 && g_winKeyState[KEY_ShiftL])
|
|
|
|
return TRUE;
|
|
|
|
break;
|
2005-07-05 19:52:35 +02:00
|
|
|
default:
|
2012-03-21 20:55:09 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2005-07-05 19:52:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Only on shift release message is sent even if both are pressed.
|
|
|
|
* Fix this here
|
|
|
|
*/
|
2012-03-21 20:55:09 +01:00
|
|
|
void
|
|
|
|
winFixShiftKeys(int iScanCode)
|
2005-07-05 19:52:35 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
if (GetKeyState(VK_SHIFT) & 0x8000)
|
|
|
|
return;
|
2005-07-05 19:52:35 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (iScanCode == KEY_ShiftL && g_winKeyState[KEY_ShiftR])
|
|
|
|
winSendKeyEvent(KEY_ShiftR, FALSE);
|
|
|
|
if (iScanCode == KEY_ShiftR && g_winKeyState[KEY_ShiftL])
|
|
|
|
winSendKeyEvent(KEY_ShiftL, FALSE);
|
2005-07-05 19:52:35 +02:00
|
|
|
}
|