Question
Mouse interrupt handling This example is designed to ask you to clean the screen by clicking mouse. In the code, the following line must be
Mouse interrupt handling
This example is designed to ask you to clean the screen by clicking mouse.
In the code, the following line must be included:
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
In addition, VK_LBUTTON, VK_RBUTTON, VK_MBUTTON indicate left button, Right button, Middle button respectively.
//Example
#include
#include
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0) //Must have this line
using namespace std;
int main()
{
while (1)
{
printf("Trick or treat. Smell my feet. Give me something good to eat. ONLY CLICK TO CLEAN THE SCREEN ");
if (KEY_DOWN(VK_LBUTTON))
{
printf("Left click to clean the screen. Pause 1 second.");
Sleep(1000);//pause 1 second
system("cls");//Clean the screen
}
if (KEY_DOWN(VK_RBUTTON))
{
printf("Right click to clean the screen. Pause 1 second.");
Sleep(1000);//pause 1 second
system("cls");//Clean the screen
}
if (KEY_DOWN(VK_MBUTTON))
{
printf("Middle click to clean the screen. Pause 1 second.");
Sleep(1000);//pause 1 second
system("cls");//Clean the screen
}
Sleep(20); //set time interval.
}
return 0;
}
- Does the code below work as well? Please explain the effect of { } in the if clause.
if (KEY_DOWN(VK_MBUTTON))
printf("Middle click to clean the screen. Pause 1 second.");
Sleep(1000);//pause 1 second
system("cls");//Clean the screen
- How the function Sleep(1000) works?
- Please try to design a new feature and modify the code. Show your code below.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started