ReactOS 0.4.16-dev-122-g325d74c
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
10static HHOOK hKbdHook, hKbdLLHook;
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
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;
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",
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}
static HHOOK hKbdHook
Definition: GetKeyState.c:10
LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam)
Definition: GetKeyState.c:12
void Test_GetKeyState()
Definition: GetKeyState.c:100
static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: GetKeyState.c:57
static HWND CreateTestWindow()
Definition: GetKeyState.c:66
static HHOOK hKbdLLHook
Definition: GetKeyState.c:10
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
Definition: GetKeyState.c:33
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
HINSTANCE hInstance
Definition: charmap.c:19
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define CALLBACK
Definition: compat.h:35
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
#define assert(x)
Definition: debug.h:53
unsigned int BOOL
Definition: ntddk_ex.h:94
static HWND hWndTest
Definition: input.c:63
unsigned int UINT
Definition: ndis.h:50
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
HBRUSH hbrBackground
Definition: winuser.h:3173
HICON hIcon
Definition: winuser.h:3171
HINSTANCE hInstance
Definition: winuser.h:3170
HCURSOR hCursor
Definition: winuser.h:3172
int cbWndExtra
Definition: winuser.h:3169
UINT style
Definition: winuser.h:3166
LPCSTR lpszMenuName
Definition: winuser.h:3174
LPCSTR lpszClassName
Definition: winuser.h:3175
WNDPROC lpfnWndProc
Definition: winuser.h:3167
int cbClsExtra
Definition: winuser.h:3168
Definition: inflate.c:139
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define CS_VREDRAW
Definition: winuser.h:658
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
#define WH_KEYBOARD
Definition: winuser.h:32
#define COLOR_WINDOW
Definition: winuser.h:921
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define HWND_TOPMOST
Definition: winuser.h:1211
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4318
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define SWP_NOMOVE
Definition: winuser.h:1247
#define CS_HREDRAW
Definition: winuser.h:653
BOOL WINAPI SetForegroundWindow(_In_ HWND)
#define IDC_ARROW
Definition: winuser.h:687
#define SWP_NOSIZE
Definition: winuser.h:1248
#define SetWindowsHookEx
Definition: winuser.h:5868
#define LLKHF_ALTDOWN
Definition: winuser.h:2650
#define IDI_APPLICATION
Definition: winuser.h:704
struct tagKBDLLHOOKSTRUCT * PKBDLLHOOKSTRUCT
ATOM WINAPI RegisterClassA(_In_ CONST WNDCLASSA *)
BOOL WINAPI UnhookWindowsHookEx(_In_ HHOOK)
HICON WINAPI LoadIconA(_In_opt_ HINSTANCE hInstance, _In_ LPCSTR lpIconName)
Definition: cursoricon.c:2112
#define PM_REMOVE
Definition: winuser.h:1199
BOOL WINAPI UpdateWindow(_In_ HWND)
#define WM_SYSKEYUP
Definition: winuser.h:1723
#define PeekMessage
Definition: winuser.h:5842
#define WH_KEYBOARD_LL
Definition: winuser.h:43
VOID WINAPI keybd_event(_In_ BYTE, _In_ BYTE, _In_ DWORD, _In_ ULONG_PTR)
#define CW_USEDEFAULT
Definition: winuser.h:225
LRESULT WINAPI CallNextHookEx(_In_opt_ HHOOK, _In_ int, _In_ WPARAM, _In_ LPARAM)
#define SW_SHOW
Definition: winuser.h:778
SHORT WINAPI GetAsyncKeyState(_In_ int)
BOOL WINAPI DestroyWindow(_In_ HWND)
#define KEYEVENTF_KEYUP
Definition: winuser.h:1105
#define WM_SYSKEYDOWN
Definition: winuser.h:1722
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2142
SHORT WINAPI GetKeyState(_In_ int)
#define VK_LMENU
Definition: winuser.h:2289
#define VK_MENU
Definition: winuser.h:2207