当前位置: 技术问答>linux和unix
获取系统事件通知
来源: 互联网 发布时间:2016-06-07
本文导语: linux下有没有类似于windows下的HOOK一类的东西,可以获得系统消息通知,譬如我希望在用户按下键盘时获得一个通知,在用户移动鼠标时获得一个通知尼? | int main() { init_keyboard();;;;; kbh...
linux下有没有类似于windows下的HOOK一类的东西,可以获得系统消息通知,譬如我希望在用户按下键盘时获得一个通知,在用户移动鼠标时获得一个通知尼?
|
int main()
{
init_keyboard();;;;;
kbhit_();
close_keyboard();
}
void init_keyboard()
{
tcgetattr(0, &initial_settings);
new_settings = initial_settings;
new_settings.c_lflag &= ~ICANON;
new_settings.c_lflag &= ~ECHO;
new_settings.c_lflag &= ~ISIG;
new_settings.c_cc[VMIN] = 1;
new_settings.c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, &new_settings);
}
void close_keyboard()
{
tcsetattr(0, TCSANOW, &initial_settings);
}
int kbhit_()
{
char ch,keyflag = 0 ;
int nread,i,j,key_len,is_ok=0;
char key_str[40];
new_settings.c_cc[VMIN] = 0;
tcsetattr(0, TCSANOW, &new_settings);
nread = read(0, key_str, 40);
new_settings.c_cc[VMIN] = 1;
tcsetattr(0, TCSANOW, &new_settings);
if (nread > 0) {
return 1;
}
return 0;
}
{
init_keyboard();;;;;
kbhit_();
close_keyboard();
}
void init_keyboard()
{
tcgetattr(0, &initial_settings);
new_settings = initial_settings;
new_settings.c_lflag &= ~ICANON;
new_settings.c_lflag &= ~ECHO;
new_settings.c_lflag &= ~ISIG;
new_settings.c_cc[VMIN] = 1;
new_settings.c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, &new_settings);
}
void close_keyboard()
{
tcsetattr(0, TCSANOW, &initial_settings);
}
int kbhit_()
{
char ch,keyflag = 0 ;
int nread,i,j,key_len,is_ok=0;
char key_str[40];
new_settings.c_cc[VMIN] = 0;
tcsetattr(0, TCSANOW, &new_settings);
nread = read(0, key_str, 40);
new_settings.c_cc[VMIN] = 1;
tcsetattr(0, TCSANOW, &new_settings);
if (nread > 0) {
return 1;
}
return 0;
}