ReactOS 0.4.15-dev-7961-gdcf9eb0
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

static HHOOK hKbdHook
 
static HHOOK hKbdLLHook
 

Function Documentation

◆ CreateTestWindow()

static HWND CreateTestWindow ( )
static

Definition at line 66 of file GetKeyState.c.

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}
static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: GetKeyState.c:57
#define msg(x)
Definition: auth_time.c:54
HINSTANCE hInstance
Definition: charmap.c:19
#define NULL
Definition: types.h:112
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
#define assert(x)
Definition: debug.h:53
static HWND hWndTest
Definition: input.c:63
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
HBRUSH hbrBackground
Definition: winuser.h:3170
HICON hIcon
Definition: winuser.h:3168
HINSTANCE hInstance
Definition: winuser.h:3167
HCURSOR hCursor
Definition: winuser.h:3169
int cbWndExtra
Definition: winuser.h:3166
UINT style
Definition: winuser.h:3163
LPCSTR lpszMenuName
Definition: winuser.h:3171
LPCSTR lpszClassName
Definition: winuser.h:3172
WNDPROC lpfnWndProc
Definition: winuser.h:3164
int cbClsExtra
Definition: winuser.h:3165
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define CS_VREDRAW
Definition: winuser.h:658
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
#define COLOR_WINDOW
Definition: winuser.h:918
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define HWND_TOPMOST
Definition: winuser.h:1208
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4315
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define SWP_NOMOVE
Definition: winuser.h:1244
#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:1245
#define IDI_APPLICATION
Definition: winuser.h:704
ATOM WINAPI RegisterClassA(_In_ CONST WNDCLASSA *)
HICON WINAPI LoadIconA(_In_opt_ HINSTANCE hInstance, _In_ LPCSTR lpIconName)
Definition: cursoricon.c:2060
#define PM_REMOVE
Definition: winuser.h:1196
BOOL WINAPI UpdateWindow(_In_ HWND)
#define PeekMessage
Definition: winuser.h:5830
#define CW_USEDEFAULT
Definition: winuser.h:225
#define SW_SHOW
Definition: winuser.h:775
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2090

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}
static HHOOK hKbdHook
Definition: GetKeyState.c:10
#define ok(value,...)
Definition: atltest.h:57
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
unsigned int BOOL
Definition: ntddk_ex.h:94
Definition: inflate.c:139
LRESULT WINAPI CallNextHookEx(_In_opt_ HHOOK, _In_ int, _In_ WPARAM, _In_ LPARAM)
SHORT WINAPI GetKeyState(_In_ int)
#define VK_LMENU
Definition: winuser.h:2286
#define VK_MENU
Definition: winuser.h:2204

Referenced by Test_GetKeyState().

◆ LowLevelKeyboardProc()

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

Definition at line 33 of file GetKeyState.c.

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}
static HHOOK hKbdLLHook
Definition: GetKeyState.c:10
#define LLKHF_ALTDOWN
Definition: winuser.h:2647
struct tagKBDLLHOOKSTRUCT * PKBDLLHOOKSTRUCT
#define WM_SYSKEYUP
Definition: winuser.h:1720
SHORT WINAPI GetAsyncKeyState(_In_ int)
#define WM_SYSKEYDOWN
Definition: winuser.h:1719

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}
LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam)
Definition: GetKeyState.c:12
static HWND CreateTestWindow()
Definition: GetKeyState.c:66
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
Definition: GetKeyState.c:33
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define WH_KEYBOARD
Definition: winuser.h:32
#define SetWindowsHookEx
Definition: winuser.h:5856
BOOL WINAPI UnhookWindowsHookEx(_In_ HHOOK)
#define WH_KEYBOARD_LL
Definition: winuser.h:43
VOID WINAPI keybd_event(_In_ BYTE, _In_ BYTE, _In_ DWORD, _In_ ULONG_PTR)
BOOL WINAPI DestroyWindow(_In_ HWND)
#define KEYEVENTF_KEYUP
Definition: winuser.h:1102

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
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

Referenced by CreateTestWindow().

Variable Documentation

◆ hKbdHook

HHOOK hKbdHook
static

Definition at line 10 of file GetKeyState.c.

Referenced by KeyboardProc(), and Test_GetKeyState().

◆ hKbdLLHook

HHOOK hKbdLLHook
static

Definition at line 10 of file GetKeyState.c.

Referenced by LowLevelKeyboardProc(), and Test_GetKeyState().