Microsoft KB Archive/35605
INFO: GetInputState Is Faster Than GetMessage() or PeekMessage()
The information in this article applies to:
- Microsoft Win32 Software Development Kit (SDK)
- Microsoft Windows Software Development Kit (SDK) versions 3.0, 3.1
This article describes a method to quickly determine whether an application for the Microsoft Windows graphical environment has any keyboard or mouse messages in its queue without calling the GetMessage or PeekMessage functions.
NOTE: In Win32, GetInputState is thread-local only.
The GetInputState function returns this information more quickly than GetMessage or PeekMessage. GetInputState returns TRUE (nonzero) if either a keyboard or mouse message is in the application's input queue. If the application must distinguish between a mouse and a keyboard message, GetInputState returns the value 2 for a keyboard and the value 1024 for a mouse message.
Because difficulties may arise if the application loses the input focus, use GetInputState only in tight loop conditions where execution speed is critical.
In Win32, message queues are not global as they are in 16-bit Windows. The message queues are local to the thread. When you call GetInputState, you are checking to see if there are mouse or keyboard messages for the calling thread only. If a window created by another thread in the application has the keyboard input waiting, GetInputState will not be able to check for those messages.
Additional query words: yield
Keywords : kbOSWinNT kbOSWin2000 kbSDKWin32 kbGrpDSUser kbOSWin kbWndw kbWndwMsg
Issue type : kbinfo
Technology : kbWin32SDKSearch kbAudDeveloper kbWin3xSearch kbSDKSearch kbWin32sSearch kbWinSDKSearch kbWinSDK300 kbWinSDK310
Last Reviewed: July 9, 2000