ReactOS  0.4.13-dev-563-g0561610
GetKeyState.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPL - See COPYING in the top level directory
4  * PURPOSE: Test for GetKeyState
5  * PROGRAMMERS: Giannis Adamopoulos
6  */
7 
8 #include "precomp.h"
9 
11 
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 }
32 
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 }
56 
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 }
65 
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 }
99 
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 }
129 
131 {
133 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
#define PeekMessage
Definition: winuser.h:5696
HHOOK hKbdHook
Definition: GetKeyState.c:10
START_TEST(GetKeyState)
Definition: GetKeyState.c:130
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
#define CALLBACK
Definition: compat.h:27
BOOL WINAPI UpdateWindow(_In_ HWND)
HWND hWnd
Definition: settings.c:17
int cbClsExtra
Definition: winuser.h:3118
#define assert(x)
Definition: debug.h:53
#define CS_HREDRAW
Definition: winuser.h:648
LPCSTR lpszMenuName
Definition: winuser.h:3124
#define HWND_TOPMOST
Definition: winuser.h:1194
#define IDI_APPLICATION
Definition: winuser.h:699
UINT_PTR WPARAM
Definition: windef.h:207
HBRUSH hbrBackground
Definition: winuser.h:3123
#define VK_MENU
Definition: winuser.h:2158
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
static HWND CreateTestWindow()
Definition: GetKeyState.c:66
BOOL WINAPI DestroyWindow(_In_ HWND)
#define COLOR_WINDOW
Definition: winuser.h:908
WPARAM wParam
Definition: combotst.c:138
HICON WINAPI LoadIconA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2029
int cbWndExtra
Definition: winuser.h:3119
HINSTANCE hInstance
Definition: charmap.c:20
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok(value,...)
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4184
HCURSOR hCursor
Definition: winuser.h:3122
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define SW_SHOW
Definition: winuser.h:769
SHORT WINAPI GetKeyState(_In_ int)
static HWND hWndTest
Definition: input.c:68
#define CS_VREDRAW
Definition: winuser.h:653
#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:5722
#define VK_LMENU
Definition: winuser.h:2240
SHORT WINAPI GetAsyncKeyState(_In_ int)
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
LPCSTR lpszClassName
Definition: winuser.h:3125
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2059
BOOL WINAPI UnhookWindowsHookEx(_In_ HHOOK)
UINT style
Definition: winuser.h:3116
#define SWP_NOSIZE
Definition: winuser.h:1230
LRESULT WINAPI CallNextHookEx(_In_opt_ HHOOK, _In_ int, _In_ WPARAM, _In_ LPARAM)
HINSTANCE hInstance
Definition: winuser.h:3120
#define LLKHF_ALTDOWN
Definition: winuser.h:2601
#define WM_SYSKEYUP
Definition: winuser.h:1696
static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: GetKeyState.c:57
void Test_GetKeyState()
Definition: GetKeyState.c:100
unsigned int UINT
Definition: ndis.h:50
WNDPROC lpfnWndProc
Definition: winuser.h:3117
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
Definition: GetKeyState.c:33
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
#define WH_KEYBOARD
Definition: winuser.h:32
#define WM_SYSKEYDOWN
Definition: winuser.h:1695
#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
LONG_PTR LRESULT
Definition: windef.h:209
LPARAM lParam
Definition: combotst.c:139
struct tagKBDLLHOOKSTRUCT * PKBDLLHOOKSTRUCT
ATOM WINAPI RegisterClassA(_In_ CONST WNDCLASSA *)
HICON hIcon
Definition: winuser.h:3121