Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 1 | /* |
Ulrich Weigand | d1b919c | 1998-11-08 12:19:23 +0000 | [diff] [blame] | 2 | * KEYBOARD driver |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright 1993 Bob Amstadt |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 5 | * Copyright 1996 Albrecht Kleine |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 6 | * Copyright 1997 David Faure |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 7 | * Copyright 1998 Morten Welinder |
Ulrich Weigand | d1b919c | 1998-11-08 12:19:23 +0000 | [diff] [blame] | 8 | * Copyright 1998 Ulrich Weigand |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 9 | * |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 10 | */ |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 11 | |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 12 | #include <stdlib.h> |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 13 | #include <string.h> |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 14 | #include <ctype.h> |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 15 | |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 16 | #include "windef.h" |
François Gouget | 44a1822 | 2000-12-19 04:53:20 +0000 | [diff] [blame] | 17 | #include "winbase.h" |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 18 | #include "wingdi.h" |
Marcus Meissner | 61afa33 | 1999-02-22 10:16:00 +0000 | [diff] [blame] | 19 | #include "winuser.h" |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 20 | #include "win.h" |
Alexandre Julliard | 28c3a1b | 2000-03-20 18:21:19 +0000 | [diff] [blame] | 21 | #include "user.h" |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 22 | #include "message.h" |
Ulrich Weigand | 24dd5d9 | 1999-09-20 18:49:02 +0000 | [diff] [blame] | 23 | #include "callback.h" |
| 24 | #include "builtin16.h" |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 25 | #include "debugtools.h" |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 26 | #include "winerror.h" |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 27 | |
Alexandre Julliard | 07d0c31 | 2000-10-26 21:50:59 +0000 | [diff] [blame] | 28 | DEFAULT_DEBUG_CHANNEL(keyboard); |
Alexandre Julliard | 4b62618 | 2001-10-17 17:50:02 +0000 | [diff] [blame] | 29 | |
| 30 | #include "pshpack1.h" |
| 31 | typedef struct _KBINFO |
| 32 | { |
| 33 | BYTE Begin_First_Range; |
| 34 | BYTE End_First_Range; |
| 35 | BYTE Begin_Second_Range; |
| 36 | BYTE End_Second_Range; |
| 37 | WORD StateSize; |
| 38 | } KBINFO, *LPKBINFO; |
| 39 | #include "poppack.h" |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 40 | |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 41 | /**********************************************************************/ |
| 42 | |
Alexandre Julliard | 4b62618 | 2001-10-17 17:50:02 +0000 | [diff] [blame] | 43 | typedef VOID CALLBACK (*LPKEYBD_EVENT_PROC)(BYTE,BYTE,DWORD,DWORD); |
| 44 | |
| 45 | static LPKEYBD_EVENT_PROC DefKeybEventProc; |
| 46 | static LPBYTE pKeyStateTable; |
| 47 | |
| 48 | /*********************************************************************** |
| 49 | * KEYBOARD_CallKeybdEventProc |
| 50 | */ |
| 51 | static VOID WINAPI KEYBOARD_CallKeybdEventProc( FARPROC16 proc, |
| 52 | BYTE bVk, BYTE bScan, |
| 53 | DWORD dwFlags, DWORD dwExtraInfo ) |
| 54 | { |
| 55 | CONTEXT86 context; |
| 56 | |
| 57 | memset( &context, 0, sizeof(context) ); |
| 58 | context.SegCs = SELECTOROF( proc ); |
| 59 | context.Eip = OFFSETOF( proc ); |
| 60 | context.Eax = bVk | ((dwFlags & KEYEVENTF_KEYUP)? 0x8000 : 0); |
| 61 | context.Ebx = bScan | ((dwFlags & KEYEVENTF_EXTENDEDKEY) ? 0x100 : 0); |
| 62 | context.Esi = LOWORD( dwExtraInfo ); |
| 63 | context.Edi = HIWORD( dwExtraInfo ); |
| 64 | |
| 65 | wine_call_to_16_regs_short( &context, 0 ); |
| 66 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 67 | |
Ulrich Weigand | d1b919c | 1998-11-08 12:19:23 +0000 | [diff] [blame] | 68 | /*********************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 69 | * Inquire (KEYBOARD.1) |
Ulrich Weigand | d1b919c | 1998-11-08 12:19:23 +0000 | [diff] [blame] | 70 | */ |
| 71 | WORD WINAPI KEYBOARD_Inquire(LPKBINFO kbInfo) |
| 72 | { |
Patrik Stridvall | e35d636 | 1998-12-07 09:13:40 +0000 | [diff] [blame] | 73 | kbInfo->Begin_First_Range = 0; |
| 74 | kbInfo->End_First_Range = 0; |
| 75 | kbInfo->Begin_Second_Range = 0; |
| 76 | kbInfo->End_Second_Range = 0; |
| 77 | kbInfo->StateSize = 16; |
| 78 | |
| 79 | return sizeof(KBINFO); |
Ulrich Weigand | d1b919c | 1998-11-08 12:19:23 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /*********************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 83 | * Enable (KEYBOARD.2) |
Ulrich Weigand | d1b919c | 1998-11-08 12:19:23 +0000 | [diff] [blame] | 84 | */ |
Alexandre Julliard | 4b62618 | 2001-10-17 17:50:02 +0000 | [diff] [blame] | 85 | VOID WINAPI KEYBOARD_Enable( FARPROC16 proc, LPBYTE lpKeyState ) |
Ulrich Weigand | d1b919c | 1998-11-08 12:19:23 +0000 | [diff] [blame] | 86 | { |
Alexandre Julliard | 4b62618 | 2001-10-17 17:50:02 +0000 | [diff] [blame] | 87 | if (DefKeybEventProc) THUNK_Free( (FARPROC)DefKeybEventProc ); |
| 88 | DefKeybEventProc = (LPKEYBD_EVENT_PROC)THUNK_Alloc( proc, (RELAY)KEYBOARD_CallKeybdEventProc ); |
| 89 | pKeyStateTable = lpKeyState; |
Ulrich Weigand | 24dd5d9 | 1999-09-20 18:49:02 +0000 | [diff] [blame] | 90 | |
Alexandre Julliard | 4b62618 | 2001-10-17 17:50:02 +0000 | [diff] [blame] | 91 | memset( lpKeyState, 0, 256 ); /* all states to false */ |
Ulrich Weigand | 24dd5d9 | 1999-09-20 18:49:02 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Ulrich Weigand | d1b919c | 1998-11-08 12:19:23 +0000 | [diff] [blame] | 94 | /*********************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 95 | * Disable (KEYBOARD.3) |
Ulrich Weigand | d1b919c | 1998-11-08 12:19:23 +0000 | [diff] [blame] | 96 | */ |
| 97 | VOID WINAPI KEYBOARD_Disable(VOID) |
| 98 | { |
Ulrich Weigand | 24dd5d9 | 1999-09-20 18:49:02 +0000 | [diff] [blame] | 99 | THUNK_Free( (FARPROC)DefKeybEventProc ); |
| 100 | |
Patrik Stridvall | e35d636 | 1998-12-07 09:13:40 +0000 | [diff] [blame] | 101 | DefKeybEventProc = NULL; |
| 102 | pKeyStateTable = NULL; |
Ulrich Weigand | d1b919c | 1998-11-08 12:19:23 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Ulrich Weigand | d1b919c | 1998-11-08 12:19:23 +0000 | [diff] [blame] | 105 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 106 | /********************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 107 | * SetSpeed (KEYBOARD.7) |
Alexandre Julliard | 4220b29 | 1999-07-11 17:20:01 +0000 | [diff] [blame] | 108 | */ |
| 109 | WORD WINAPI SetSpeed16(WORD unused) |
| 110 | { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 111 | FIXME("(%04x): stub\n", unused); |
Alexandre Julliard | 4220b29 | 1999-07-11 17:20:01 +0000 | [diff] [blame] | 112 | return 0xffff; |
| 113 | } |
| 114 | |
| 115 | /********************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 116 | * ScreenSwitchEnable (KEYBOARD.100) |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 117 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 118 | VOID WINAPI ScreenSwitchEnable16(WORD unused) |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 119 | { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 120 | FIXME("(%04x): stub\n", unused); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 124 | * OemKeyScan (KEYBOARD.128) |
| 125 | * OemKeyScan (USER32.@) |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 126 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 127 | DWORD WINAPI OemKeyScan(WORD wOemChar) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 128 | { |
Andreas Mohr | e15badb | 2001-10-21 15:18:15 +0000 | [diff] [blame] | 129 | TRACE("(%d)\n", wOemChar); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 130 | |
Patrik Stridvall | e35d636 | 1998-12-07 09:13:40 +0000 | [diff] [blame] | 131 | return wOemChar; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 134 | /********************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 135 | * VkKeyScan (KEYBOARD.129) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 136 | */ |
Ulrich Weigand | d1b919c | 1998-11-08 12:19:23 +0000 | [diff] [blame] | 137 | WORD WINAPI VkKeyScan16(CHAR cChar) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 138 | { |
Alexandre Julliard | 4b62618 | 2001-10-17 17:50:02 +0000 | [diff] [blame] | 139 | return VkKeyScanA( cChar ); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 142 | /****************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 143 | * GetKeyboardType (KEYBOARD.130) |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 144 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 145 | INT16 WINAPI GetKeyboardType16(INT16 nTypeFlag) |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 146 | { |
Alexandre Julliard | 4b62618 | 2001-10-17 17:50:02 +0000 | [diff] [blame] | 147 | return GetKeyboardType( nTypeFlag ); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 150 | /****************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 151 | * MapVirtualKey (KEYBOARD.131) |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 152 | * |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 153 | * MapVirtualKey translates keycodes from one format to another |
| 154 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 155 | UINT16 WINAPI MapVirtualKey16(UINT16 wCode, UINT16 wMapType) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 156 | { |
Alexandre Julliard | 4b62618 | 2001-10-17 17:50:02 +0000 | [diff] [blame] | 157 | return MapVirtualKeyA(wCode,wMapType); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 160 | /**************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 161 | * GetKBCodePage (KEYBOARD.132) |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 162 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 163 | INT16 WINAPI GetKBCodePage16(void) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 164 | { |
Dmitry Timoshkov | 97d5abc | 2000-12-29 19:47:53 +0000 | [diff] [blame] | 165 | return GetKBCodePage(); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 168 | /**************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 169 | * GetKeyNameText (KEYBOARD.133) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 170 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 171 | INT16 WINAPI GetKeyNameText16(LONG lParam, LPSTR lpBuffer, INT16 nSize) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 172 | { |
Alexandre Julliard | 4b62618 | 2001-10-17 17:50:02 +0000 | [diff] [blame] | 173 | return GetKeyNameTextA( lParam, lpBuffer, nSize ); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 176 | /**************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 177 | * ToAscii (KEYBOARD.4) |
Patrik Stridvall | e35d636 | 1998-12-07 09:13:40 +0000 | [diff] [blame] | 178 | * |
| 179 | * The ToAscii function translates the specified virtual-key code and keyboard |
| 180 | * state to the corresponding Windows character or characters. |
| 181 | * |
| 182 | * If the specified key is a dead key, the return value is negative. Otherwise, |
| 183 | * it is one of the following values: |
| 184 | * Value Meaning |
| 185 | * 0 The specified virtual key has no translation for the current state of the keyboard. |
| 186 | * 1 One Windows character was copied to the buffer. |
| 187 | * 2 Two characters were copied to the buffer. This usually happens when a |
| 188 | * dead-key character (accent or diacritic) stored in the keyboard layout cannot |
| 189 | * be composed with the specified virtual key to form a single character. |
| 190 | * |
| 191 | * FIXME : should do the above (return 2 for non matching deadchar+char combinations) |
| 192 | * |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 193 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 194 | INT16 WINAPI ToAscii16(UINT16 virtKey,UINT16 scanCode, LPBYTE lpKeyState, |
| 195 | LPVOID lpChar, UINT16 flags) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 196 | { |
Dmitry Timoshkov | 8a31634 | 2000-10-25 21:34:31 +0000 | [diff] [blame] | 197 | return ToAscii( virtKey, scanCode, lpKeyState, lpChar, flags ); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 198 | } |
Patrik Stridvall | e35d636 | 1998-12-07 09:13:40 +0000 | [diff] [blame] | 199 | |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 200 | /*********************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 201 | * MessageBeep (USER.104) |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 202 | */ |
Alexandre Julliard | 946a444 | 2000-07-30 13:50:27 +0000 | [diff] [blame] | 203 | void WINAPI MessageBeep16( UINT16 i ) |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 204 | { |
Alexandre Julliard | 946a444 | 2000-07-30 13:50:27 +0000 | [diff] [blame] | 205 | MessageBeep( i ); |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Alexandre Julliard | 946a444 | 2000-07-30 13:50:27 +0000 | [diff] [blame] | 208 | /*********************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 209 | * MessageBeep (USER32.@) |
Alexandre Julliard | 946a444 | 2000-07-30 13:50:27 +0000 | [diff] [blame] | 210 | */ |
| 211 | BOOL WINAPI MessageBeep( UINT i ) |
| 212 | { |
Alexandre Julliard | c6a835a | 2001-05-05 00:49:15 +0000 | [diff] [blame] | 213 | BOOL active = TRUE; |
| 214 | SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE ); |
| 215 | if (active) USER_Driver.pBeep(); |
Alexandre Julliard | 946a444 | 2000-07-30 13:50:27 +0000 | [diff] [blame] | 216 | return TRUE; |
| 217 | } |