NO MFC Programming 03 - Detecting Global Keyboard

zhaozj2021-02-16  45

(If you do not enter a focus, how to detect the status of the keyboard?)

There is a "soil" method to do, but it does not necessarily use things that it takes back? Because this approach detects the overall keyboard status (or even mouse buttons), you are not clear whether it is controlled for your own programs.

· The source program is as follows:

// file name: WinMain.cpp

// Specify the next sentence to explain that the program is independent of the MFC, can speed up the compilation speed #define win32_lean_and_mean // Say no to mfc !! #include

// name: WinMain () // Program entry // ----------------------- WinApi Winmain (Hinstance Hinstance, Hinstance Hprevinstance, LPSTR LPCMDLINE, INT NCMDSHOW) {

MessageBox (NULL, "if you want to exit / n / n press esc.", "By` Sea Breeze ", MB_ok | MB_TOPMOST

While (1) {

// The following test is the inspection button status, if it is ESC to exit

IF (getasynckeystate & 0x8000) // Source Project

{MessageBox (NULL, "Success Exited!", "- congratulate!", MB_OK | MB_TOPMOST); EXITPROCESS (NULL);} // ends ...

Sleep (5); // Do optimized, actually use 1 to achieve a relatively small CPU occupancy}

MessageBox (Null, "IF you read this message," `sea breeze", MB_OK; RETURN NULL;}

· The Essence Essence in IF (getasynckeyState & 0x8000) It is detected by the ESC key, specified by the virtual key VK_ESCAPE.

· If you want to specify other keys, you must have other virtual keys. Although the following methods are left, but you can quickly find what you need.

(The source program "is selected in the VC environment, let it go back. Then click on the right button above, select "Go to DEFINITION OF VK_ESCAPE", (Choose Yes) and then go to the file as defined below (Winuser.h). Did you see the constant of VK_EScape? There are other virtual keys, such as VK_Lshift represents the left SHIFT key (or even the left mouse button), study it.

Ok, as the beginning of this article, this is a "soil" approach, which even captures the buttons of others.

Is it very annoying? `Sea Breeze October 03, 2002 AM 11:15

-------------------------- Attach yourself:

转载请注明原文地址:https://www.9cbs.com/read-24607.html

New Post(0)