INFO: GetInputState Is Faster Than GetMessage or PeekMessage

ID: Q35605


The information in this article applies to:


SUMMARY

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.


MORE INFORMATION

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          : kbNTOS kbGrpUser kbWinOS kbWndw kbWndwMsg 
Version           : 
Platform          : 
Issue type        : kbinfo 

Last Reviewed: March 5, 1999