ReactOS  0.4.15-dev-1374-g8d3e80e
GetKeyState.c File Reference
#include "precomp.h"
Include dependency graph for GetKeyState.c:

Go to the source code of this file.

Functions

LRESULT CALLBACK KeyboardProc (int code, WPARAM wParam, LPARAM lParam)
 
LRESULT CALLBACK LowLevelKeyboardProc (int nCode, WPARAM wParam, LPARAM lParam)
 
static LRESULT CALLBACK WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
static HWND CreateTestWindow ()
 
void Test_GetKeyState ()
 
 START_TEST (GetKeyState)
 

Variables

HHOOK hKbdHook
 
HHOOK hKbdLLHook
 

Function Documentation

◆ CreateTestWindow()

static HWND CreateTestWindow ( )
static

Definition at line 66 of file GetKeyState.c.

67 {
68  MSG msg;
69  WNDCLASSA wclass;
71  HWND hWndTest;
72 
73  wclass.lpszClassName = "InputSysKeyTestClass";
74  wclass.style = CS_HREDRAW | CS_VREDRAW;
75  wclass.lpfnWndProc = WndProc;
76  wclass.hInstance = hInstance;
77  wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
78  wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
79  wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
80  wclass.lpszMenuName = 0;
81  wclass.cbClsExtra = 0;
82  wclass.cbWndExtra = 0;
83  RegisterClassA( &wclass );
84  /* create the test window that will receive the keystrokes */
85  hWndTest = CreateWindowA( wclass.lpszClassName, "InputSysKeyTest",
86  WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, 100, 100,
87  NULL, NULL, hInstance, NULL);
88  assert( hWndTest );
93 
94  /* flush pending messages */
95  while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
96 
97  return hWndTest;
98 }
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
#define PeekMessage
Definition: winuser.h:5805
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
BOOL WINAPI UpdateWindow(_In_ HWND)
int cbClsExtra
Definition: winuser.h:3140
#define assert(x)
Definition: debug.h:53
#define CS_HREDRAW
Definition: winuser.h:648
LPCSTR lpszMenuName
Definition: winuser.h:3146
#define HWND_TOPMOST
Definition: winuser.h:1194
#define IDI_APPLICATION
Definition: winuser.h:699
HBRUSH hbrBackground
Definition: winuser.h:3145
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define COLOR_WINDOW
Definition: winuser.h:908
HICON WINAPI LoadIconA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2029
int cbWndExtra
Definition: winuser.h:3141
HINSTANCE hInstance
Definition: charmap.c:20
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4290
HCURSOR hCursor
Definition: winuser.h:3144
#define CW_USEDEFAULT
Definition: winuser.h:225
#define SW_SHOW
Definition: winuser.h:769
static HWND hWndTest
Definition: input.c:63
#define CS_VREDRAW
Definition: winuser.h:653
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
LPCSTR lpszClassName
Definition: winuser.h:3147
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2059
UINT style
Definition: winuser.h:3138
#define SWP_NOSIZE
Definition: winuser.h:1230
HINSTANCE hInstance
Definition: winuser.h:3142
static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: GetKeyState.c:57
#define NULL
Definition: types.h:112
WNDPROC lpfnWndProc
Definition: winuser.h:3139
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
BOOL WINAPI SetForegroundWindow(_In_ HWND)
#define SWP_NOMOVE
Definition: winuser.h:1229
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define PM_REMOVE
Definition: winuser.h:1182
ATOM WINAPI RegisterClassA(_In_ CONST WNDCLASSA *)
HICON hIcon
Definition: winuser.h:3143

Referenced by Test_GetKeyState().

◆ KeyboardProc()

LRESULT CALLBACK KeyboardProc ( int  code,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 12 of file GetKeyState.c.

13 {
14  BOOL pressed = !(lParam & (1<<31));
15  BOOL altPressed = lParam & (1<<29);
16 
17  if(pressed)
18  {
19  ok(altPressed,"\n");
20  ok((GetKeyState(VK_MENU) & 0x8000), "Alt should not be pressed\n");\
21  ok((GetKeyState(VK_LMENU) & 0x8000), "Left alt should not be pressed\n");\
22  }
23  else
24  {
25  ok(!altPressed,"\n");
26  ok(!(GetKeyState(VK_MENU) & 0x8000), "Alt should be pressed\n");
27  ok(!(GetKeyState(VK_LMENU) & 0x8000), "Left alt should be pressed\n");
28  }
29 
31 }
HHOOK hKbdHook
Definition: GetKeyState.c:10
#define VK_MENU
Definition: winuser.h:2179
WPARAM wParam
Definition: combotst.c:138
unsigned int BOOL
Definition: ntddk_ex.h:94
SHORT WINAPI GetKeyState(_In_ int)
#define VK_LMENU
Definition: winuser.h:2261
Definition: inflate.c:139
LRESULT WINAPI CallNextHookEx(_In_opt_ HHOOK, _In_ int, _In_ WPARAM, _In_ LPARAM)
#define ok(value,...)
Definition: atltest.h:57
LPARAM lParam
Definition: combotst.c:139

Referenced by Test_GetKeyState().

◆ LowLevelKeyboardProc()

LRESULT CALLBACK LowLevelKeyboardProc ( int  nCode,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 33 of file GetKeyState.c.

34 {
36 
37  if(wParam == WM_SYSKEYDOWN)
38  {
39  ok(pLLHook->flags & LLKHF_ALTDOWN,"Didn't get LLKHF_ALTDOWN flag\n");
40  ok((GetAsyncKeyState (VK_MENU) & 0x8000), "Alt should not be pressed in global kbd status\n");
41  ok(!(GetKeyState(VK_MENU) & 0x8000), "Alt should not be pressed in queue state\n");
42  ok(!(GetAsyncKeyState (VK_LMENU) & 0x8000), "Left alt should not be pressed in global kbd status\n");
43  ok(!(GetKeyState(VK_LMENU) & 0x8000), "Left alt should not be pressed in queue state\n");
44  }
45  else if(wParam == WM_SYSKEYUP)
46  {
47  ok(!(pLLHook->flags & LLKHF_ALTDOWN),"got LLKHF_ALTDOWN flag\n");
48  ok(!(GetAsyncKeyState (VK_MENU) & 0x8000), "Alt should not be pressed in global kbd status\n");
49  ok((GetKeyState(VK_MENU) & 0x8000), "Alt should be pressed in queue state\n");
50  ok(!(GetAsyncKeyState (VK_LMENU) & 0x8000), "Left alt should not be pressed in global kbd status\n");
51  ok((GetKeyState(VK_LMENU) & 0x8000), "Left alt should be pressed in queue state\n");
52  }
53 
54  return CallNextHookEx(hKbdLLHook, nCode, wParam, lParam);
55 }
HHOOK hKbdLLHook
Definition: GetKeyState.c:10
#define VK_MENU
Definition: winuser.h:2179
WPARAM wParam
Definition: combotst.c:138
SHORT WINAPI GetKeyState(_In_ int)
#define VK_LMENU
Definition: winuser.h:2261
SHORT WINAPI GetAsyncKeyState(_In_ int)
LRESULT WINAPI CallNextHookEx(_In_opt_ HHOOK, _In_ int, _In_ WPARAM, _In_ LPARAM)
#define LLKHF_ALTDOWN
Definition: winuser.h:2622
#define WM_SYSKEYUP
Definition: winuser.h:1702
#define ok(value,...)
Definition: atltest.h:57
#define WM_SYSKEYDOWN
Definition: winuser.h:1701
LPARAM lParam
Definition: combotst.c:139
struct tagKBDLLHOOKSTRUCT * PKBDLLHOOKSTRUCT

Referenced by Test_GetKeyState().

◆ START_TEST()

START_TEST ( GetKeyState  )

Definition at line 130 of file GetKeyState.c.

131 {
133 }
void Test_GetKeyState()
Definition: GetKeyState.c:100

◆ Test_GetKeyState()

void Test_GetKeyState ( )

Definition at line 100 of file GetKeyState.c.

101 {
102  HWND hwnd;
103  MSG msg;
104 
106 
109 
110  ok(hKbdHook!=NULL," \n");
111  ok(hKbdLLHook!=NULL," \n");
112 
113  keybd_event(VK_LMENU, 0, 0,0);
114 
115  while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
116 
118 
119  //fixme this hangs the test
120  //while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessageA( &msg );
121 
123 
124  while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
125 
128 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
#define PeekMessage
Definition: winuser.h:5805
HHOOK hKbdHook
Definition: GetKeyState.c:10
HHOOK hKbdLLHook
Definition: GetKeyState.c:10
#define KEYEVENTF_KEYUP
Definition: winuser.h:1092
LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam)
Definition: GetKeyState.c:12
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
static HWND CreateTestWindow()
Definition: GetKeyState.c:66
BOOL WINAPI DestroyWindow(_In_ HWND)
#define WH_KEYBOARD_LL
Definition: winuser.h:43
VOID WINAPI keybd_event(_In_ BYTE, _In_ BYTE, _In_ DWORD, _In_ ULONG_PTR)
#define SetWindowsHookEx
Definition: winuser.h:5831
#define VK_LMENU
Definition: winuser.h:2261
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
BOOL WINAPI UnhookWindowsHookEx(_In_ HHOOK)
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
Definition: GetKeyState.c:33
#define msg(x)
Definition: auth_time.c:54
#define WH_KEYBOARD
Definition: winuser.h:32
#define PM_REMOVE
Definition: winuser.h:1182

Referenced by START_TEST().

◆ WndProc()

static LRESULT CALLBACK WndProc ( HWND  hWnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 57 of file GetKeyState.c.

58 {
59  if(msg == WM_SYSKEYDOWN)
60  {
61  ok(wParam == VK_MENU, "Got wrong wParam in WM_SYSKEYDOWN (%d instead of %d)\n", wParam, VK_MENU );
62  }
63  return DefWindowProcA( hWnd, msg, wParam, lParam );
64 }
HWND hWnd
Definition: settings.c:17
#define VK_MENU
Definition: winuser.h:2179
WPARAM wParam
Definition: combotst.c:138
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define ok(value,...)
Definition: atltest.h:57
#define msg(x)
Definition: auth_time.c:54
#define WM_SYSKEYDOWN
Definition: winuser.h:1701
LPARAM lParam
Definition: combotst.c:139

Referenced by CreateTestWindow().

Variable Documentation

◆ hKbdHook

HHOOK hKbdHook

Definition at line 10 of file GetKeyState.c.

Referenced by KeyboardProc(), and Test_GetKeyState().

◆ hKbdLLHook

HHOOK hKbdLLHook

Definition at line 10 of file GetKeyState.c.

Referenced by LowLevelKeyboardProc(), and Test_GetKeyState().