c語言下對鍵盤滑鼠的控制
#include <iostream>
#include <windows.h>
#include <stdlib.h>
using namespace std;
void GetMousePos()
{
POINT point;
GetCursorPos(&point);
cout<<"X:"<<point.x<<"/tY:"<<point.y<<endl<<endl;
};
void MoveMouse()
{
cout<<"請輸入滑鼠新座標:"<<endl;
int a,b;
cout<<"x座標:";
cin>>a;
cout<<"y座標:";
cin>>b;
SetCursorPos(a,b);
cout<<endl<<endl;
};
void keyboard()
{
char keych;
cout<<"CTRL-A:螢幕顯示AAAA"<<endl;
cout<<"CTRL-B:螢幕顯示BBBB"<<endl;
cout<<"CTRL-C:螢幕顯示CCCC"<<endl;
cout<<"CTRL-D:螢幕顯示DDDD"<<endl;
cin>>keych;
switch(keych)
{
case 01: cout<<"/nAAAA/n/n";break;
case 02: cout<<"/nBBBB/n/n";break;
case 03: cout<<"/nCCCC/n/n";break;
case 04: cout<<"/nDDDD/n/n";break;
default: exit(1);break;
}
}
void main(){
int i;
A:cout<<"/t##################/n"<<endl;
B:cout<<"1.鍵盤組合鍵演示"<<endl<<"2.滑鼠擊右鍵清屏"<<endl<<
"3.獲取滑鼠當前螢幕位置"<<endl<<"4.改變滑鼠所在位置"<<endl;
cin>>i;
switch(i){
case 1:keyboard();goto B;break;
case 2:while(1)
{
if(GetKeyState(VK_RBUTTON)<0)
{
system("cls");break;
}
}
goto A;
case 3:GetMousePos();goto B;break;
case 4:MoveMouse();goto B;break;
}
}