2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: win32ss/user/winsrv/consrv/frontends/input.c
5 * PURPOSE: Common Front-Ends Input functions
6 * PROGRAMMERS: Jeffrey Morlan
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
10 /* INCLUDES *******************************************************************/
13 #include "include/conio.h"
14 #include "include/term.h"
21 /* PRIVATE FUNCTIONS **********************************************************/
24 ConioGetShiftState(PBYTE KeyState
, LPARAM lParam
)
28 if (KeyState
[VK_CAPITAL
] & 0x01)
31 if (KeyState
[VK_NUMLOCK
] & 0x01)
34 if (KeyState
[VK_SCROLL
] & 0x01)
35 ssOut
|= SCROLLLOCK_ON
;
37 if (KeyState
[VK_SHIFT
] & 0x80)
38 ssOut
|= SHIFT_PRESSED
;
40 if (KeyState
[VK_LCONTROL
] & 0x80)
41 ssOut
|= LEFT_CTRL_PRESSED
;
42 if (KeyState
[VK_RCONTROL
] & 0x80)
43 ssOut
|= RIGHT_CTRL_PRESSED
;
45 if (KeyState
[VK_LMENU
] & 0x80)
46 ssOut
|= LEFT_ALT_PRESSED
;
47 if (KeyState
[VK_RMENU
] & 0x80)
48 ssOut
|= RIGHT_ALT_PRESSED
;
50 /* See WM_CHAR MSDN documentation for instance */
51 if (lParam
& 0x01000000)
52 ssOut
|= ENHANCED_KEY
;
58 ConioProcessKey(PCONSOLE Console
, MSG
* msg
)
60 static BYTE KeyState
[256] = { 0 };
61 /* MSDN mentions that you should use the last virtual key code received
62 * when putting a virtual key identity to a WM_CHAR message since multiple
63 * or translated keys may be involved. */
64 static UINT LastVirtualKey
= 0;
70 BOOLEAN Fake
; // synthesized, not a real event
71 BOOLEAN NotChar
; // message should not be used to return a character
75 DPRINT1("No Active Console!\n");
79 VirtualScanCode
= HIWORD(msg
->lParam
) & 0xFF;
80 Down
= msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_CHAR
||
81 msg
->message
== WM_SYSKEYDOWN
|| msg
->message
== WM_SYSCHAR
;
83 GetKeyboardState(KeyState
);
84 ShiftState
= ConioGetShiftState(KeyState
, msg
->lParam
);
86 if (msg
->message
== WM_CHAR
|| msg
->message
== WM_SYSCHAR
)
88 VirtualKeyCode
= LastVirtualKey
;
89 UnicodeChar
= msg
->wParam
;
96 VirtualKeyCode
= msg
->wParam
;
97 RetChars
= ToUnicodeEx(VirtualKeyCode
,
104 UnicodeChar
= (1 == RetChars
? Chars
[0] : 0);
107 if (TermProcessKeyCallback(Console
,
117 Fake
= UnicodeChar
&&
118 (msg
->message
!= WM_CHAR
&& msg
->message
!= WM_SYSCHAR
&&
119 msg
->message
!= WM_KEYUP
&& msg
->message
!= WM_SYSKEYUP
);
120 NotChar
= (msg
->message
!= WM_CHAR
&& msg
->message
!= WM_SYSCHAR
);
121 if (NotChar
) LastVirtualKey
= msg
->wParam
;
123 DPRINT("CONSRV: %s %s %s %s %02x %02x '%lc' %04x\n",
124 Down
? "down" : "up ",
125 (msg
->message
== WM_CHAR
|| msg
->message
== WM_SYSCHAR
) ?
127 Fake
? "fake" : "real",
128 NotChar
? "notc" : "char",
131 (UnicodeChar
>= L
' ') ? UnicodeChar
: L
'.',
136 /* Send the key press to the console driver */
137 ConDrvProcessKey(Console
,
143 KeyState
[VK_CONTROL
]);