ReactOS 0.4.15-dev-8119-g4fb2fdb
keytrans.c File Reference
#include <usetup.h>
#include "keytrans.h"
#include <debug.h>
Include dependency graph for keytrans.c:

Go to the source code of this file.

Classes

struct  _SCANTOASCII
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _SCANTOASCII SCANTOASCII
 
typedef struct _SCANTOASCIIPSCANTOASCII
 

Functions

static void IntUpdateControlKeyState (HANDLE hConsoleInput, LPDWORD State, PKEYBOARD_INPUT_DATA InputData)
 
static DWORD IntVKFromKbdInput (PKEYBOARD_INPUT_DATA InputData, DWORD KeyState)
 
static UCHAR IntAsciiFromInput (PKEYBOARD_INPUT_DATA InputData, DWORD KeyState)
 
NTSTATUS IntTranslateKey (HANDLE hConsoleInput, PKEYBOARD_INPUT_DATA InputData, KEY_EVENT_RECORD *Event)
 

Variables

static WORD KeyTable []
 
static WORD KeyTableEnhanced []
 
static WORD KeyTableNumlock []
 
SCANTOASCII ScanToAscii []
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 31 of file keytrans.c.

Typedef Documentation

◆ PSCANTOASCII

◆ SCANTOASCII

Function Documentation

◆ IntAsciiFromInput()

static UCHAR IntAsciiFromInput ( PKEYBOARD_INPUT_DATA  InputData,
DWORD  KeyState 
)
static

Definition at line 376 of file keytrans.c.

377{
378 UINT Counter = 0;
379 USHORT Enhanced = 0;
380
381 if (KeyState & ENHANCED_KEY) Enhanced = 1;
382
383 while (ScanToAscii[Counter].ScanCode != 0) {
384 if ((ScanToAscii[Counter].ScanCode == InputData->MakeCode) &&
385 (ScanToAscii[Counter].Enhanced == Enhanced)) {
386 if (ScanToAscii[Counter].NumLock) {
387 if ((KeyState & NUMLOCK_ON) &&
388 !(KeyState & SHIFT_PRESSED)) {
390 } else {
391 return ScanToAscii[Counter].Normal;
392 }
393 }
394
395 if ((KeyState & CAPSLOCK_ON) && ScanToAscii[Counter].bCAPS)
396 KeyState ^= SHIFT_PRESSED;
397
398 if (KeyState & SHIFT_PRESSED)
399 return ScanToAscii[Counter].Shift;
400
401 return ScanToAscii[Counter].Normal;
402 }
403 Counter++;
404 }
405
406 return 0;
407}
UINT ScanCode
Definition: VirtualKey.c:24
SCANTOASCII ScanToAscii[]
Definition: keytrans.c:172
unsigned int UINT
Definition: ndis.h:50
unsigned short USHORT
Definition: pedump.c:61
USHORT Enhanced
Definition: keytrans.c:165
UCHAR NumLock
Definition: keytrans.c:168
UCHAR Shift
Definition: keytrans.c:167
UCHAR Normal
Definition: keytrans.c:166
static LARGE_INTEGER Counter
Definition: clock.c:43
#define CAPSLOCK_ON
Definition: wincon.h:144
#define SHIFT_PRESSED
Definition: wincon.h:141
#define NUMLOCK_ON
Definition: wincon.h:142
#define ENHANCED_KEY
Definition: wincon.h:145

Referenced by IntTranslateKey().

◆ IntTranslateKey()

NTSTATUS IntTranslateKey ( HANDLE  hConsoleInput,
PKEYBOARD_INPUT_DATA  InputData,
KEY_EVENT_RECORD Event 
)

Definition at line 417 of file keytrans.c.

418{
419 static DWORD dwControlKeyState;
420
422
423 if (!(InputData->Flags & KEY_BREAK))
424 Event->bKeyDown = TRUE;
425 else
426 Event->bKeyDown = FALSE;
427
428 Event->wRepeatCount = 1;
429 Event->wVirtualScanCode = InputData->MakeCode;
430
431 DPRINT("Translating: %x\n", InputData->MakeCode);
432
433 IntUpdateControlKeyState(hConsoleInput, &dwControlKeyState, InputData);
434 Event->dwControlKeyState = dwControlKeyState;
435
436 if (InputData->Flags & KEY_E0)
437 Event->dwControlKeyState |= ENHANCED_KEY;
438
439 Event->wVirtualKeyCode = IntVKFromKbdInput(InputData,
440 Event->dwControlKeyState);
441
442 DPRINT("Result: %x\n", Event->wVirtualKeyCode);
443
444 if (Event->bKeyDown) {
445 Event->uChar.AsciiChar =
446 IntAsciiFromInput(InputData,
447 Event->dwControlKeyState);
448 DPRINT("Char: %x\n", Event->uChar.AsciiChar);
449 } else {
450 Event->uChar.AsciiChar = 0;
451 }
452
453 return STATUS_SUCCESS;
454}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned long DWORD
Definition: ntddk_ex.h:95
static void IntUpdateControlKeyState(HANDLE hConsoleInput, LPDWORD State, PKEYBOARD_INPUT_DATA InputData)
Definition: keytrans.c:251
static UCHAR IntAsciiFromInput(PKEYBOARD_INPUT_DATA InputData, DWORD KeyState)
Definition: keytrans.c:376
static DWORD IntVKFromKbdInput(PKEYBOARD_INPUT_DATA InputData, DWORD KeyState)
Definition: keytrans.c:358
#define KEY_BREAK
Definition: ntddkbd.h:71
#define KEY_E0
Definition: ntddkbd.h:72
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by PeekConsoleInput(), and ReadConsoleInput().

◆ IntUpdateControlKeyState()

static void IntUpdateControlKeyState ( HANDLE  hConsoleInput,
LPDWORD  State,
PKEYBOARD_INPUT_DATA  InputData 
)
static

Definition at line 251 of file keytrans.c.

252{
253 DWORD Value = 0;
254 DWORD oldState, newState;
255
256 if (InputData->Flags & KEY_E1) /* Only the pause key has E1 */
257 return;
258
259 oldState = newState = *State;
260
261 if (!(InputData->Flags & KEY_E0)) {
262 switch (InputData->MakeCode) {
263 case 0x2a:
264 case 0x36:
266 break;
267
268 case 0x1d:
270 break;
271
272 case 0x38:
274 break;
275
276 case 0x3A:
277 if (!(InputData->Flags & KEY_BREAK))
278 newState ^= CAPSLOCK_ON;
279 break;
280
281 case 0x45:
282 if (!(InputData->Flags & KEY_BREAK))
283 newState ^= NUMLOCK_ON;
284 break;
285
286 case 0x46:
287 if (!(InputData->Flags & KEY_BREAK))
288 newState ^= SCROLLLOCK_ON;
289 break;
290
291 default:
292 return;
293 }
294 } else {
295 switch (InputData->MakeCode) {
296 case 0x1d:
298 break;
299
300 case 0x38:
302 break;
303
304 default:
305 return;
306 }
307 }
308
309 /* Check if the state of the indicators has been changed */
310 if ((oldState ^ newState) & (NUMLOCK_ON | CAPSLOCK_ON | SCROLLLOCK_ON))
311 {
315
316 kip.LedFlags = 0;
317 kip.UnitId = 0;
318
319 if ((newState & NUMLOCK_ON))
321
322 if ((newState & CAPSLOCK_ON))
324
325 if ((newState & SCROLLLOCK_ON))
327
328 /* Update the state of the leds on primary keyboard */
329 DPRINT("NtDeviceIoControlFile dwLeds=%x\n", kip.LedFlags);
330
332 hConsoleInput,
333 NULL,
334 NULL,
335 NULL,
338 &kip,
339 sizeof(kip),
340 NULL,
341 0);
342
343 if (!NT_SUCCESS(Status))
344 {
345 DPRINT1("NtDeviceIoControlFile(IOCTL_KEYBOARD_SET_INDICATORS) failed (Status %lx)\n", Status);
346 }
347 } else
348 /* Normal press/release state handling */
349 if (InputData->Flags & KEY_BREAK)
350 newState &= ~Value;
351 else
352 newState |= Value;
353
354 *State = newState;
355}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define KEYBOARD_CAPS_LOCK_ON
Definition: ntddkbd.h:81
#define IOCTL_KEYBOARD_SET_INDICATORS
Definition: ntddkbd.h:47
#define KEYBOARD_SCROLL_LOCK_ON
Definition: ntddkbd.h:83
#define KEY_E1
Definition: ntddkbd.h:73
#define KEYBOARD_NUM_LOCK_ON
Definition: ntddkbd.h:82
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
#define LEFT_CTRL_PRESSED
Definition: wincon.h:140
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:139
#define RIGHT_ALT_PRESSED
Definition: wincon.h:137
#define SCROLLLOCK_ON
Definition: wincon.h:143
#define LEFT_ALT_PRESSED
Definition: wincon.h:138

Referenced by IntTranslateKey().

◆ IntVKFromKbdInput()

static DWORD IntVKFromKbdInput ( PKEYBOARD_INPUT_DATA  InputData,
DWORD  KeyState 
)
static

Definition at line 358 of file keytrans.c.

359{
360 if (!(KeyState & ENHANCED_KEY)) {
361 if ((KeyState & NUMLOCK_ON) &&
362 KeyTableNumlock[InputData->MakeCode & 0x7f]) {
363 DPRINT("Numlock, using %x\n",
364 InputData->MakeCode & 0x7f);
365 return KeyTableNumlock[InputData->MakeCode & 0x7f];
366 }
367 DPRINT("Not enhanced, using %x\n", InputData->MakeCode & 0x7f);
368 return KeyTable[InputData->MakeCode & 0x7f];
369 }
370
371 DPRINT("Enhanced, using %x\n", InputData->MakeCode & 0x7f);
372 return KeyTableEnhanced[InputData->MakeCode & 0x7f];
373}
static WORD KeyTable[]
Definition: keytrans.c:34
static WORD KeyTableEnhanced[]
Definition: keytrans.c:77
static WORD KeyTableNumlock[]
Definition: keytrans.c:120

Referenced by IntTranslateKey().

Variable Documentation

◆ KeyTable

WORD KeyTable[]
static

Definition at line 34 of file keytrans.c.

Referenced by IntVKFromKbdInput().

◆ KeyTableEnhanced

WORD KeyTableEnhanced[]
static

Definition at line 77 of file keytrans.c.

Referenced by IntVKFromKbdInput().

◆ KeyTableNumlock

WORD KeyTableNumlock[]
static

Definition at line 120 of file keytrans.c.

Referenced by IntVKFromKbdInput().

◆ ScanToAscii

SCANTOASCII ScanToAscii[]

Definition at line 172 of file keytrans.c.

Referenced by IntAsciiFromInput().