ReactOS  0.4.15-dev-488-gc7a1924
input.c File Reference
#include "consrv.h"
#include "include/term.h"
#include "coninput.h"
#include <debug.h>
Include dependency graph for input.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static DWORD ConioGetShiftState (PBYTE KeyState, LPARAM lParam)
 
VOID NTAPI ConioProcessKey (PCONSRV_CONSOLE Console, MSG *msg)
 
DWORD ConioEffectiveCursorSize (PCONSRV_CONSOLE Console, DWORD Scale)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file input.c.

Function Documentation

◆ ConioEffectiveCursorSize()

DWORD ConioEffectiveCursorSize ( PCONSRV_CONSOLE  Console,
DWORD  Scale 
)

Definition at line 182 of file input.c.

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 }
unsigned long DWORD
Definition: ntddk_ex.h:95
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
CConsole Console

Referenced by GuiPaintCaret().

◆ ConioGetShiftState()

static DWORD ConioGetShiftState ( PBYTE  KeyState,
LPARAM  lParam 
)
static

Definition at line 23 of file input.c.

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 */
53  if (lParam & 0x01000000)
54  ssOut |= ENHANCED_KEY;
55 
56  return ssOut;
57 }
#define SCROLLLOCK_ON
Definition: wincon.h:143
#define VK_RMENU
Definition: winuser.h:2262
#define SHIFT_PRESSED
Definition: wincon.h:141
#define VK_SHIFT
Definition: winuser.h:2177
#define LEFT_ALT_PRESSED
Definition: wincon.h:138
#define ENHANCED_KEY
Definition: wincon.h:145
unsigned long DWORD
Definition: ntddk_ex.h:95
#define LEFT_CTRL_PRESSED
Definition: wincon.h:140
#define VK_RCONTROL
Definition: winuser.h:2260
#define VK_LMENU
Definition: winuser.h:2261
#define VK_SCROLL
Definition: winuser.h:2255
#define VK_NUMLOCK
Definition: winuser.h:2254
#define VK_CAPITAL
Definition: winuser.h:2181
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:139
#define VK_LCONTROL
Definition: winuser.h:2259
LPARAM lParam
Definition: combotst.c:139
#define NUMLOCK_ON
Definition: wincon.h:142
#define RIGHT_ALT_PRESSED
Definition: wincon.h:137
#define CAPSLOCK_ON
Definition: wincon.h:144

Referenced by ConioProcessKey().

◆ ConioProcessKey()

VOID NTAPI ConioProcessKey ( PCONSRV_CONSOLE  Console,
MSG msg 
)

Definition at line 60 of file input.c.

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 = FALSE;
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;
172  er.Event.KeyEvent.wRepeatCount = 1;
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 }
union _KEY_EVENT_RECORD::@3198 uChar
WCHAR UnicodeChar
Definition: wincon.h:245
WORD wVirtualScanCode
Definition: wincon.h:243
#define WM_CHAR
Definition: winuser.h:1699
VOID ConioDrawConsole(PCONSRV_CONSOLE Console)
Definition: terminal.c:860
DWORD dwControlKeyState
Definition: wincon.h:248
#define VK_DOWN
Definition: winuser.h:2202
int32_t INT
Definition: typedefs.h:57
WORD wVirtualKeyCode
Definition: wincon.h:242
WORD wRepeatCount
Definition: wincon.h:241
#define VK_UP
Definition: winuser.h:2200
unsigned int BOOL
Definition: ntddk_ex.h:94
#define KEY_EVENT
Definition: wincon.h:128
#define WM_SYSCHAR
Definition: winuser.h:1703
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define WM_KEYDOWN
Definition: winuser.h:1697
void DPRINT(...)
Definition: polytest.cpp:61
#define LEFT_ALT_PRESSED
Definition: wincon.h:138
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define WM_KEYUP
Definition: winuser.h:1698
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:278
unsigned long DWORD
Definition: ntddk_ex.h:95
_Check_return_ BOOL WINAPI GetKeyboardState(_Out_writes_(256) PBYTE lpKeyState)
static const WCHAR L[]
Definition: oid.c:1250
static DWORD ConioGetShiftState(PBYTE KeyState, LPARAM lParam)
Definition: input.c:23
int WINAPI ToUnicodeEx(UINT wVirtKey, UINT wScanCode, CONST BYTE *lpKeyState, LPWSTR pwszBuff, int cchBuff, UINT wFlags, HKL dwhkl)
Definition: input.c:481
unsigned char BYTE
Definition: xxhash.c:193
#define WM_SYSKEYUP
Definition: winuser.h:1702
unsigned int UINT
Definition: ndis.h:50
CConsole Console
WORD EventType
Definition: wincon.h:276
#define DPRINT1
Definition: precomp.h:8
#define msg(x)
Definition: auth_time.c:54
#define WM_SYSKEYDOWN
Definition: winuser.h:1701
#define HIWORD(l)
Definition: typedefs.h:246
union _INPUT_RECORD::@3199 Event
#define RIGHT_ALT_PRESSED
Definition: wincon.h:137
NTSTATUS ConioProcessInputEvent(PCONSRV_CONSOLE Console, PINPUT_RECORD InputEvent)
Definition: coninput.c:201

Referenced by OnKey().