ReactOS 0.4.16-dev-340-g0540c21
input.c
Go to the documentation of this file.
1/*
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)
8 */
9
10/* INCLUDES *******************************************************************/
11
12#include "consrv.h"
13#include "include/term.h"
14#include "coninput.h"
15
16#define NDEBUG
17#include <debug.h>
18
19
20/* PRIVATE FUNCTIONS **********************************************************/
21
22static DWORD
24{
25 DWORD ssOut = 0;
26
27 if (KeyState[VK_CAPITAL] & 0x01)
28 ssOut |= CAPSLOCK_ON;
29
30 if (KeyState[VK_NUMLOCK] & 0x01)
31 ssOut |= NUMLOCK_ON;
32
33 if (KeyState[VK_SCROLL] & 0x01)
34 ssOut |= SCROLLLOCK_ON;
35
36 if (KeyState[VK_SHIFT] & 0x80)
37 // || (KeyState[VK_LSHIFT] & 0x80) || (KeyState[VK_RSHIFT] & 0x80)
38 ssOut |= SHIFT_PRESSED;
39
40 if (KeyState[VK_LCONTROL] & 0x80)
41 ssOut |= LEFT_CTRL_PRESSED;
42 if (KeyState[VK_RCONTROL] & 0x80)
43 ssOut |= RIGHT_CTRL_PRESSED;
44 // if (KeyState[VK_CONTROL] & 0x80) { ... }
45
46 if (KeyState[VK_LMENU] & 0x80)
47 ssOut |= LEFT_ALT_PRESSED;
48 if (KeyState[VK_RMENU] & 0x80)
49 ssOut |= RIGHT_ALT_PRESSED;
50 // if (KeyState[VK_MENU] & 0x80) { ... }
51
52 /* See WM_CHAR MSDN documentation for instance */
54 ssOut |= ENHANCED_KEY;
55
56 return ssOut;
57}
58
61{
62 static BYTE KeyState[256] = { 0 };
63 /* MSDN mentions that you should use the last virtual key code received
64 * when putting a virtual key identity to a WM_CHAR message since multiple
65 * or translated keys may be involved. */
66 static UINT LastVirtualKey = 0;
67 DWORD ShiftState;
68 WCHAR UnicodeChar;
69 UINT VirtualKeyCode;
70 UINT VirtualScanCode;
71 BOOL Down;
72 BOOLEAN Fake; // Synthesized, not a real event
73 BOOLEAN NotChar; // Message should not be used to return a character
74
75 INPUT_RECORD er;
76
77 if (Console == NULL)
78 {
79 DPRINT1("No Active Console!\n");
80 return;
81 }
82
83 VirtualScanCode = HIWORD(msg->lParam) & 0xFF;
84 Down = msg->message == WM_KEYDOWN || msg->message == WM_CHAR ||
85 msg->message == WM_SYSKEYDOWN || msg->message == WM_SYSCHAR;
86
87 GetKeyboardState(KeyState);
88 ShiftState = ConioGetShiftState(KeyState, msg->lParam);
89
90 if (msg->message == WM_CHAR || msg->message == WM_SYSCHAR)
91 {
92 VirtualKeyCode = LastVirtualKey;
93 UnicodeChar = msg->wParam;
94 }
95 else
96 {
97 WCHAR Chars[2];
98 INT RetChars = 0;
99
100 VirtualKeyCode = msg->wParam;
101 RetChars = ToUnicodeEx(VirtualKeyCode,
102 VirtualScanCode,
103 KeyState,
104 Chars,
105 2,
106 0,
107 NULL);
108 UnicodeChar = (RetChars == 1 ? Chars[0] : 0);
109 }
110
111 Fake = UnicodeChar &&
112 (msg->message != WM_CHAR && msg->message != WM_SYSCHAR &&
113 msg->message != WM_KEYUP && msg->message != WM_SYSKEYUP);
114 NotChar = (msg->message != WM_CHAR && msg->message != WM_SYSCHAR);
115 if (NotChar) LastVirtualKey = msg->wParam;
116
117 DPRINT("CONSRV: %s %s %s %s %02x %02x '%lc' %04x\n",
118 Down ? "down" : "up ",
119 (msg->message == WM_CHAR || msg->message == WM_SYSCHAR) ?
120 "char" : "key ",
121 Fake ? "fake" : "real",
122 NotChar ? "notc" : "char",
123 VirtualScanCode,
124 VirtualKeyCode,
125 (UnicodeChar >= L' ') ? UnicodeChar : L'.',
126 ShiftState);
127
128 if (Fake) return;
129
130//
131// FIXME: Scrolling via keyboard shortcuts must be done differently,
132// without touching the internal VirtualY variable.
133//
134#if 0
135 if ( (ShiftState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) != 0 &&
136 (VirtualKeyCode == VK_UP || VirtualKeyCode == VK_DOWN) )
137 {
138 if (!Down) return;
139
140 /* Scroll up or down */
141 if (VirtualKeyCode == VK_UP)
142 {
143 /* Only scroll up if there is room to scroll up into */
144 if (Console->ActiveBuffer->CursorPosition.Y != Console->ActiveBuffer->ScreenBufferSize.Y - 1)
145 {
146 Console->ActiveBuffer->VirtualY = (Console->ActiveBuffer->VirtualY +
147 Console->ActiveBuffer->ScreenBufferSize.Y - 1) %
148 Console->ActiveBuffer->ScreenBufferSize.Y;
149 Console->ActiveBuffer->CursorPosition.Y++;
150 }
151 }
152 else
153 {
154 /* Only scroll down if there is room to scroll down into */
155 if (Console->ActiveBuffer->CursorPosition.Y != 0)
156 {
157 Console->ActiveBuffer->VirtualY = (Console->ActiveBuffer->VirtualY + 1) %
158 Console->ActiveBuffer->ScreenBufferSize.Y;
159 Console->ActiveBuffer->CursorPosition.Y--;
160 }
161 }
162
164 return;
165 }
166#endif
167
168 /* Send the key press to the console driver */
169
170 er.EventType = KEY_EVENT;
171 er.Event.KeyEvent.bKeyDown = Down;
173 er.Event.KeyEvent.wVirtualKeyCode = VirtualKeyCode;
174 er.Event.KeyEvent.wVirtualScanCode = VirtualScanCode;
175 er.Event.KeyEvent.uChar.UnicodeChar = UnicodeChar;
176 er.Event.KeyEvent.dwControlKeyState = ShiftState;
177
179}
180
181DWORD
183{
184 DWORD Size = (Console->ActiveBuffer->CursorInfo.dwSize * Scale + 99) / 100;
185 /* If line input in progress, perhaps adjust for insert toggle */
186 if (Console->LineBuffer && !Console->LineComplete && (Console->InsertMode ? !Console->LineInsertToggle : Console->LineInsertToggle))
187 return (Size * 2 <= Scale) ? (Size * 2) : (Size / 2);
188 return Size;
189}
190
191/* EOF */
unsigned char BOOLEAN
CConsole Console
#define msg(x)
Definition: auth_time.c:54
#define DPRINT1
Definition: precomp.h:8
LPARAM lParam
Definition: combotst.c:139
NTSTATUS ConioProcessInputEvent(PCONSRV_CONSOLE Console, PINPUT_RECORD InputEvent)
Definition: coninput.c:201
#define NULL
Definition: types.h:112
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
#define DPRINT
Definition: sndvol32.h:73
union _INPUT_RECORD::@3287 Event
WORD EventType
Definition: wincon.h:273
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:275
WORD wVirtualScanCode
Definition: wincon.h:243
DWORD dwControlKeyState
Definition: wincon.h:248
WORD wVirtualKeyCode
Definition: wincon.h:242
WORD wRepeatCount
Definition: wincon.h:241
union _KEY_EVENT_RECORD::@3286 uChar
WCHAR UnicodeChar
Definition: wincon.h:245
VOID ConioDrawConsole(PCONSRV_CONSOLE Console)
Definition: terminal.c:860
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define NTAPI
Definition: typedefs.h:36
int32_t INT
Definition: typedefs.h:58
#define HIWORD(l)
Definition: typedefs.h:247
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
static DWORD ConioGetShiftState(PBYTE KeyState, LPARAM lParam)
Definition: input.c:23
VOID NTAPI ConioProcessKey(PCONSRV_CONSOLE Console, MSG *msg)
Definition: input.c:60
DWORD ConioEffectiveCursorSize(PCONSRV_CONSOLE Console, DWORD Scale)
Definition: input.c:182
#define CAPSLOCK_ON
Definition: wincon.h:144
#define LEFT_CTRL_PRESSED
Definition: wincon.h:140
#define SHIFT_PRESSED
Definition: wincon.h:141
#define NUMLOCK_ON
Definition: wincon.h:142
#define KEY_EVENT
Definition: wincon.h:128
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:139
#define RIGHT_ALT_PRESSED
Definition: wincon.h:137
#define ENHANCED_KEY
Definition: wincon.h:145
#define SCROLLLOCK_ON
Definition: wincon.h:143
#define LEFT_ALT_PRESSED
Definition: wincon.h:138
LONG_PTR LPARAM
Definition: windef.h:208
#define WM_KEYUP
Definition: winuser.h:1719
#define VK_CAPITAL
Definition: winuser.h:2209
#define VK_SCROLL
Definition: winuser.h:2283
#define KF_EXTENDED
Definition: winuser.h:2449
#define VK_UP
Definition: winuser.h:2228
_Check_return_ BOOL WINAPI GetKeyboardState(_Out_writes_(256) PBYTE lpKeyState)
#define VK_LCONTROL
Definition: winuser.h:2287
#define VK_RCONTROL
Definition: winuser.h:2288
#define WM_SYSCHAR
Definition: winuser.h:1724
#define VK_RMENU
Definition: winuser.h:2290
#define WM_SYSKEYUP
Definition: winuser.h:1723
#define WM_CHAR
Definition: winuser.h:1720
#define VK_DOWN
Definition: winuser.h:2230
int WINAPI ToUnicodeEx(_In_ UINT wVirtKey, _In_ UINT wScanCode, _In_reads_bytes_(256) CONST BYTE *lpKeyState, _Out_writes_(cchBuff) LPWSTR pwszBuff, _In_ int cchBuff, _In_ UINT wFlags, _In_opt_ HKL dwhkl)
#define VK_NUMLOCK
Definition: winuser.h:2282
#define VK_SHIFT
Definition: winuser.h:2205
#define WM_KEYDOWN
Definition: winuser.h:1718
#define WM_SYSKEYDOWN
Definition: winuser.h:1722
#define VK_LMENU
Definition: winuser.h:2289
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193