2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for GetKeyState
5 * PROGRAMMERS: Giannis Adamopoulos
13 HHOOK hKbdHook
, hKbdLLHook
;
15 LRESULT CALLBACK
KeyboardProc(int code
, WPARAM wParam
, LPARAM lParam
)
17 BOOL pressed
= !(lParam
& (1<<31));
18 BOOL altPressed
= lParam
& (1<<29);
23 ok((GetKeyState(VK_MENU
) & 0x8000), "Alt should not be pressed\n");\
24 ok((GetKeyState(VK_LMENU
) & 0x8000), "Left alt should not be pressed\n");\
29 ok(!(GetKeyState(VK_MENU
) & 0x8000), "Alt should be pressed\n");
30 ok(!(GetKeyState(VK_LMENU
) & 0x8000), "Left alt should be pressed\n");
33 return CallNextHookEx(hKbdHook
, code
, wParam
, lParam
);
36 LRESULT CALLBACK
LowLevelKeyboardProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
38 PKBDLLHOOKSTRUCT pLLHook
= (PKBDLLHOOKSTRUCT
)lParam
;
40 if(wParam
== WM_SYSKEYDOWN
)
42 ok(pLLHook
->flags
& LLKHF_ALTDOWN
,"Didn't get LLKHF_ALTDOWN flag\n");
43 ok((GetAsyncKeyState (VK_MENU
) & 0x8000), "Alt should not be pressed in global kbd status\n");
44 ok(!(GetKeyState(VK_MENU
) & 0x8000), "Alt should not be pressed in queue state\n");
45 ok(!(GetAsyncKeyState (VK_LMENU
) & 0x8000), "Left alt should not be pressed in global kbd status\n");
46 ok(!(GetKeyState(VK_LMENU
) & 0x8000), "Left alt should not be pressed in queue state\n");
48 else if(wParam
== WM_SYSKEYUP
)
50 ok(!(pLLHook
->flags
& LLKHF_ALTDOWN
),"got LLKHF_ALTDOWN flag\n");
51 ok(!(GetAsyncKeyState (VK_MENU
) & 0x8000), "Alt should not be pressed in global kbd status\n");
52 ok((GetKeyState(VK_MENU
) & 0x8000), "Alt should be pressed in queue state\n");
53 ok(!(GetAsyncKeyState (VK_LMENU
) & 0x8000), "Left alt should not be pressed in global kbd status\n");
54 ok((GetKeyState(VK_LMENU
) & 0x8000), "Left alt should be pressed in queue state\n");
57 return CallNextHookEx(hKbdLLHook
, nCode
, wParam
, lParam
);
60 static LRESULT CALLBACK
WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
62 if(msg
== WM_SYSKEYDOWN
)
64 ok(wParam
== VK_MENU
, "Got wrong wParam in WM_SYSKEYDOWN (%d instead of %d)\n", wParam
, VK_MENU
);
66 return DefWindowProcA( hWnd
, msg
, wParam
, lParam
);
69 static HWND
CreateTestWindow()
73 HANDLE hInstance
= GetModuleHandleA( NULL
);
76 wclass
.lpszClassName
= "InputSysKeyTestClass";
77 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
78 wclass
.lpfnWndProc
= WndProc
;
79 wclass
.hInstance
= hInstance
;
80 wclass
.hIcon
= LoadIconA( 0, IDI_APPLICATION
);
81 wclass
.hCursor
= LoadCursorA( NULL
, IDC_ARROW
);
82 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
83 wclass
.lpszMenuName
= 0;
84 wclass
.cbClsExtra
= 0;
85 wclass
.cbWndExtra
= 0;
86 RegisterClassA( &wclass
);
87 /* create the test window that will receive the keystrokes */
88 hWndTest
= CreateWindowA( wclass
.lpszClassName
, "InputSysKeyTest",
89 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0, 100, 100,
90 NULL
, NULL
, hInstance
, NULL
);
92 ShowWindow( hWndTest
, SW_SHOW
);
93 SetWindowPos( hWndTest
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
94 SetForegroundWindow( hWndTest
);
95 UpdateWindow( hWndTest
);
97 /* flush pending messages */
98 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
103 void Test_GetKeyState()
108 hwnd
= CreateTestWindow();
110 hKbdHook
= SetWindowsHookEx(WH_KEYBOARD
, KeyboardProc
, GetModuleHandleA( NULL
), 0);
111 hKbdLLHook
= SetWindowsHookEx(WH_KEYBOARD_LL
, LowLevelKeyboardProc
, GetModuleHandleA( NULL
), 0);
113 ok(hKbdHook
!=NULL
," \n");
114 ok(hKbdLLHook
!=NULL
," \n");
116 keybd_event(VK_LMENU
, 0, 0,0);
118 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
120 keybd_event(VK_LMENU
, 0, KEYEVENTF_KEYUP
,0);
122 //fixme this hangs the test
123 //while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessageA( &msg );
127 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
129 UnhookWindowsHookEx (hKbdHook
);
130 UnhookWindowsHookEx (hKbdLLHook
);
133 START_TEST(GetKeyState
)