ReactOS  0.4.13-dev-247-g0f29b3f
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 190 of file input.c.

191 {
192  DWORD Size = (Console->ActiveBuffer->CursorInfo.dwSize * Scale + 99) / 100;
193  /* If line input in progress, perhaps adjust for insert toggle */
194  if (Console->LineBuffer && !Console->LineComplete && (Console->InsertMode ? !Console->LineInsertToggle : Console->LineInsertToggle))
195  return (Size * 2 <= Scale) ? (Size * 2) : (Size / 2);
196  return Size;
197 }
unsigned long DWORD
Definition: ntddk_ex.h:95
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
CConsole Console

◆ 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  ssOut |= SHIFT_PRESSED;
38 
39  if (KeyState[VK_LCONTROL] & 0x80)
40  ssOut |= LEFT_CTRL_PRESSED;
41  if (KeyState[VK_RCONTROL] & 0x80)
42  ssOut |= RIGHT_CTRL_PRESSED;
43 
44  if (KeyState[VK_LMENU] & 0x80)
45  ssOut |= LEFT_ALT_PRESSED;
46  if (KeyState[VK_RMENU] & 0x80)
47  ssOut |= RIGHT_ALT_PRESSED;
48 
49  /* See WM_CHAR MSDN documentation for instance */
50  if (lParam & 0x01000000)
51  ssOut |= ENHANCED_KEY;
52 
53  return ssOut;
54 }
#define SCROLLLOCK_ON
Definition: wincon.h:137
#define VK_RMENU
Definition: winuser.h:2241
#define SHIFT_PRESSED
Definition: wincon.h:135
#define VK_SHIFT
Definition: winuser.h:2156
#define LEFT_ALT_PRESSED
Definition: wincon.h:132
#define ENHANCED_KEY
Definition: wincon.h:139
unsigned long DWORD
Definition: ntddk_ex.h:95
#define LEFT_CTRL_PRESSED
Definition: wincon.h:134
#define VK_RCONTROL
Definition: winuser.h:2239
#define VK_LMENU
Definition: winuser.h:2240
#define VK_SCROLL
Definition: winuser.h:2234
#define VK_NUMLOCK
Definition: winuser.h:2233
#define VK_CAPITAL
Definition: winuser.h:2160
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:133
#define VK_LCONTROL
Definition: winuser.h:2238
LPARAM lParam
Definition: combotst.c:139
#define NUMLOCK_ON
Definition: wincon.h:136
#define RIGHT_ALT_PRESSED
Definition: wincon.h:131
#define CAPSLOCK_ON
Definition: wincon.h:138

Referenced by ConioProcessKey().

◆ ConioProcessKey()

VOID NTAPI ConioProcessKey ( PCONSRV_CONSOLE  Console,
MSG msg 
)

Definition at line 57 of file input.c.

58 {
59  static BYTE KeyState[256] = { 0 };
60  /* MSDN mentions that you should use the last virtual key code received
61  * when putting a virtual key identity to a WM_CHAR message since multiple
62  * or translated keys may be involved. */
63  static UINT LastVirtualKey = 0;
64  DWORD ShiftState;
65  WCHAR UnicodeChar;
66  UINT VirtualKeyCode;
67  UINT VirtualScanCode;
68  BOOL Down = FALSE;
69  BOOLEAN Fake; // Synthesized, not a real event
70  BOOLEAN NotChar; // Message should not be used to return a character
71 
72  INPUT_RECORD er;
73 
74  if (Console == NULL)
75  {
76  DPRINT1("No Active Console!\n");
77  return;
78  }
79 
80  VirtualScanCode = HIWORD(msg->lParam) & 0xFF;
81  Down = msg->message == WM_KEYDOWN || msg->message == WM_CHAR ||
82  msg->message == WM_SYSKEYDOWN || msg->message == WM_SYSCHAR;
83 
84  GetKeyboardState(KeyState);
85  ShiftState = ConioGetShiftState(KeyState, msg->lParam);
86 
87  if (msg->message == WM_CHAR || msg->message == WM_SYSCHAR)
88  {
89  VirtualKeyCode = LastVirtualKey;
90  UnicodeChar = msg->wParam;
91  }
92  else
93  {
94  WCHAR Chars[2];
95  INT RetChars = 0;
96 
97  VirtualKeyCode = msg->wParam;
98  RetChars = ToUnicodeEx(VirtualKeyCode,
99  VirtualScanCode,
100  KeyState,
101  Chars,
102  2,
103  0,
104  NULL);
105  UnicodeChar = (RetChars == 1 ? Chars[0] : 0);
106  }
107 
108  Fake = UnicodeChar &&
109  (msg->message != WM_CHAR && msg->message != WM_SYSCHAR &&
110  msg->message != WM_KEYUP && msg->message != WM_SYSKEYUP);
111  NotChar = (msg->message != WM_CHAR && msg->message != WM_SYSCHAR);
112  if (NotChar) LastVirtualKey = msg->wParam;
113 
114  DPRINT("CONSRV: %s %s %s %s %02x %02x '%lc' %04x\n",
115  Down ? "down" : "up ",
116  (msg->message == WM_CHAR || msg->message == WM_SYSCHAR) ?
117  "char" : "key ",
118  Fake ? "fake" : "real",
119  NotChar ? "notc" : "char",
120  VirtualScanCode,
121  VirtualKeyCode,
122  (UnicodeChar >= L' ') ? UnicodeChar : L'.',
123  ShiftState);
124 
125  if (Fake) return;
126 
127  /* Process Ctrl-C and Ctrl-Break */
128  if ( Console->InputBuffer.Mode & ENABLE_PROCESSED_INPUT &&
129  Down && (VirtualKeyCode == VK_PAUSE || VirtualKeyCode == 'C') &&
130  (ShiftState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED) || KeyState[VK_CONTROL] & 0x80) )
131  {
132  DPRINT1("Console_Api Ctrl-C\n");
134 
135  if (Console->LineBuffer && !Console->LineComplete)
136  {
137  /* Line input is in progress; end it */
138  Console->LinePos = Console->LineSize = 0;
139  Console->LineComplete = TRUE;
140  }
141  return;
142  }
143 
144  if ( (ShiftState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) != 0 &&
145  (VirtualKeyCode == VK_UP || VirtualKeyCode == VK_DOWN) )
146  {
147  if (!Down) return;
148 
149  /* Scroll up or down */
150  if (VirtualKeyCode == VK_UP)
151  {
152  /* Only scroll up if there is room to scroll up into */
153  if (Console->ActiveBuffer->CursorPosition.Y != Console->ActiveBuffer->ScreenBufferSize.Y - 1)
154  {
155  Console->ActiveBuffer->VirtualY = (Console->ActiveBuffer->VirtualY +
156  Console->ActiveBuffer->ScreenBufferSize.Y - 1) %
157  Console->ActiveBuffer->ScreenBufferSize.Y;
158  Console->ActiveBuffer->CursorPosition.Y++;
159  }
160  }
161  else
162  {
163  /* Only scroll down if there is room to scroll down into */
164  if (Console->ActiveBuffer->CursorPosition.Y != 0)
165  {
166  Console->ActiveBuffer->VirtualY = (Console->ActiveBuffer->VirtualY + 1) %
167  Console->ActiveBuffer->ScreenBufferSize.Y;
168  Console->ActiveBuffer->CursorPosition.Y--;
169  }
170  }
171 
173  return;
174  }
175 
176  /* Send the key press to the console driver */
177 
178  er.EventType = KEY_EVENT;
179  er.Event.KeyEvent.bKeyDown = Down;
180  er.Event.KeyEvent.wRepeatCount = 1;
181  er.Event.KeyEvent.wVirtualKeyCode = VirtualKeyCode;
182  er.Event.KeyEvent.wVirtualScanCode = VirtualScanCode;
183  er.Event.KeyEvent.uChar.UnicodeChar = UnicodeChar;
184  er.Event.KeyEvent.dwControlKeyState = ShiftState;
185 
187 }
#define TRUE
Definition: types.h:120
WCHAR UnicodeChar
Definition: wincon.h:230
WORD wVirtualScanCode
Definition: wincon.h:228
#define WM_CHAR
Definition: winuser.h:1693
union _KEY_EVENT_RECORD::@3144 uChar
VOID ConioDrawConsole(PCONSRV_CONSOLE Console)
Definition: terminal.c:663
DWORD dwControlKeyState
Definition: wincon.h:233
#define CTRL_C_EVENT
Definition: wincon.h:65
#define VK_DOWN
Definition: winuser.h:2181
int32_t INT
Definition: typedefs.h:56
WORD wVirtualKeyCode
Definition: wincon.h:227
WORD wRepeatCount
Definition: wincon.h:226
#define VK_UP
Definition: winuser.h:2179
NTSTATUS NTAPI ConSrvConsoleProcessCtrlEvent(IN PCONSRV_CONSOLE Console, IN ULONG ProcessGroupId, IN ULONG CtrlEvent)
Definition: console.c:906
unsigned int BOOL
Definition: ntddk_ex.h:94
#define KEY_EVENT
Definition: wincon.h:122
#define WM_SYSCHAR
Definition: winuser.h:1697
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define WM_KEYDOWN
Definition: winuser.h:1691
void DPRINT(...)
Definition: polytest.cpp:61
union _INPUT_RECORD::@3145 Event
#define LEFT_ALT_PRESSED
Definition: wincon.h:132
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define WM_KEYUP
Definition: winuser.h:1692
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:263
unsigned long DWORD
Definition: ntddk_ex.h:95
_Check_return_ BOOL WINAPI GetKeyboardState(_Out_writes_(256) PBYTE lpKeyState)
#define LEFT_CTRL_PRESSED
Definition: wincon.h:134
static const WCHAR L[]
Definition: oid.c:1250
unsigned char BYTE
Definition: mem.h:68
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
#define ENABLE_PROCESSED_INPUT
Definition: wincon.h:75
#define WM_SYSKEYUP
Definition: winuser.h:1696
unsigned int UINT
Definition: ndis.h:50
#define VK_CONTROL
Definition: winuser.h:2157
CConsole Console
WORD EventType
Definition: wincon.h:261
#define DPRINT1
Definition: precomp.h:8
#define msg(x)
Definition: auth_time.c:54
#define VK_PAUSE
Definition: winuser.h:2159
#define WM_SYSKEYDOWN
Definition: winuser.h:1695
#define HIWORD(l)
Definition: typedefs.h:246
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:133
#define RIGHT_ALT_PRESSED
Definition: wincon.h:131
NTSTATUS ConioProcessInputEvent(PCONSRV_CONSOLE Console, PINPUT_RECORD InputEvent)
Definition: coninput.c:195

Referenced by GuiConsoleHandleKey(), and OnKey().