#include "stdafx.h" #include <signal.h> #include <windows.h> #include <iostream>
using namespace std;
void cs(int n) { if(n==SIGINT) { cout<<"\n你触发了黑名单"<<endl; signal(SIGINT, cs); return; } if(n==SIGBREAK){ cout<<"\n你按下了ctrl+break,现在退出程序\n"; exit(0); } }
int main() { char ch[30]; char* str[3]; bool flag=false; signal(SIGINT, cs); /*注册ctrl+c信号捕获函数*/ signal(SIGBREAK,cs); /*注册ctrl+break信号捕获函数*/
//黑名单命令 str[0]="cd"; str[1]="ls"; str[2]="dir";
while(1){
if(flag!=true){
cin>>ch;
for(int i=0;i<sizeof(str)/sizeof(str[0]);i++){ if(strcmp(ch,str[i])==0){
//组合按键 keybd_event(VK_CONTROL,0,0,0); //按下control键 keybd_event(67,0,0,0); //按下C键 keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0); keybd_event(67,0,KEYEVENTF_KEYUP,0); flag=true; } } } }
return 0; }
|
请发表评论