c语言编写键盘监控器方法

用c语言怎样编写键盘监控器,请大家帮帮忙,另外,批处理判断窗口是存在,若存在则运行xxx若不存在则跳过,这个命令应该怎样写?... 用c语言怎样编写键盘监控器,请大家帮帮忙,另外,批处理判断窗口是存在,若存在则运行xxx若不存在则跳过,这个命令应该怎样写? 展开
 我来答
匿名用户
2013-08-26
展开全部
键控程序简单事例:#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
/*======== ALL VAR==============*/
int bleft=10;
int width=52;
int height=20;
/*=========About Location===========*/
typedef struct
{
int x, y;
int xv, yv;
}Location;/*=============About Welcome=============*/
void menu()
{ printf(" welcom to coming\n");
printf(" =======================================================\n");
printf(" ! In the game please press ESc to quit! !\n");
printf(" ! Enter the game?(Y/N) !\n");
printf(" =======================================================\n");
}
/*=========About border==========*/
void bianjie()
{
int i;
for(i=0;i<bleft;i++)
printf(" ");
for(i=0;i<width;i++)
{ printf("=");
}
for(i=0;i<height;i++)
{ gotoxy(bleft,i);
printf("!");
}
for(i=0;i<height;i++)
{ gotoxy(width+bleft,i);
printf("!");
}
for(i=1;i<width;i++)
{ gotoxy(bleft+i,height-1);
printf("=");
}
}
/*==========About pro things===========
void things()
{
}*/
/*===========About Oprtion=============*/
void zhixing()
{
int i,key;
Location shili;
shili.x=bleft+1;
shili.y=1;
shili.xv=5;
shili.yv=5;
while(1)
{
key=bioskey(0);
if(key==ESC)/**/
break;
else if(key==UP)
{
for(i=0;i<shili.yv;i++)
{
if(shili.y-shili.yv>1)
{
shili.y--;
gotoxy(shili.x,shili.y+1);
printf(" ");
gotoxy(shili.x,shili.y);
printf("%c\b", 2);
}
else {
if(shili.y>1)
{
shili.y--;
gotoxy(shili.x,shili.y+1);
printf(" ");
gotoxy(shili.x,shili.y);
printf("%c\b", 2);
}
else { shili.y++;
gotoxy(shili.x,shili.y);
printf("%c\b", 2);
gotoxy(shili.x,shili.y-1);
printf(" ");
}
}
}
}
else if(key==DOWN)
{
for(i=0;i<shili.yv;i++)
{
if(shili.y+shili.yv<height)
{
shili.y++;
gotoxy(shili.x,shili.y-1);
printf(" ");
gotoxy(shili.x,shili.y);
printf("%c\b", 2);
}
else {
if(shili.y<height)
{
shili.y++;
gotoxy(shili.x,shili.y-1);
printf(" ");
gotoxy(shili.x,shili.y);
printf("%c\b", 2);
}
else { shili.y--;
gotoxy(shili.x,shili.y);
printf("%c\b", 2);
gotoxy(shili.x,shili.y+1);
printf(" ");
}
}
}
}
else if(key==LEFT)
{
for(i=0;i<shili.xv;i++)
{
if(shili.x-shili.xv>bleft)
{
shili.x--;
gotoxy(shili.x+1,shili.y);
printf(" ");
gotoxy(shili.x,shili.y);
printf("%c\b", 2);
}
else {
if(shili.x>bleft)
{
shili.x--;
gotoxy(shili.x+1,shili.y);
printf(" ");
gotoxy(shili.x,shili.y);
printf("%c\b", 2);
}
else { shili.x++;
gotoxy(shili.x,shili.y);
printf("%c\b", 2);
gotoxy(shili.x-1,shili.y);
printf(" ");
}
}
}
}
else if(key==RIGHT)
{
for(i=0;i<shili.xv;i++)
{
if(shili.x+shili.xv<width+bleft)
{
shili.x++;
gotoxy(shili.x-1,shili.y);
printf(" ");
gotoxy(shili.x,shili.y);
printf("%c\b", 2);
}
else {
if(shili.x<width+bleft)
{
shili.x++;
gotoxy(shili.x-1,shili.y);
printf(" ");
gotoxy(shili.x,shili.y);
printf("%c\b", 2);
}
else { shili.x--;
gotoxy(shili.x,shili.y);
printf("%c\b", 2);
gotoxy(shili.x+1,shili.y);
printf(" ");
}
}
}
}
}}
/**********************************/
void main()
{ char ch;
clrscr();
menu();
ch=getch();
if(ch=='N'||ch=='n')
return;
else if(ch=='Y'||ch=='y')
{ clrscr();
bianjie();
zhixing();
}
}C语言获取键值函数事例:/*函数名称: bioskey
函数原型: int bioskey(int cmd)
函数功能: 读取键盘值
函数返回: cmd=0:返回一个键盘值(ascii值放在低位,扫描码放在高位),若无按键,一直等
cmd=1:查询键盘是否按下:0-无键按下,非0-有键按下
cmd=2:返回控制键状态,返回值保存在低8位中
0-右边的shift键按下 5-已打开Scroll_Lock
1-左边的shift键按下 6-已打开Num_Lock
3-Ctrl键按下 7-已打开Caps_Lock
4-Alt键按下 8-已打开Insert
参数说明:
所属文件: <bios.h>*/
#include <stdio.h>
#include <bios.h>
#include <ctype.h>
int main()
{
int key, shift;
int lastshift;
while (1)
{
shift=bioskey(2);
if(shift!=lastshift)
printf("Shift=0x% 02x\n",shift);
if(bioskey(1))
{
key=bioskey(0);
if((key&0xFF)=='q')
break;
printf("Key=0x% 04x",key);
}
lastshift=shift;
}
return 0;
}文件存在性判断事例:#include <stdio.h>
#include <io.h>
int file_exists(char *filename);
int main()
{
printf("Does myfile.FIL exist: %s",file_exists("myfile.FIL") ? "YES" : "NO");
getch();
return 0;
}
int file_exists(char *filename)
{
return (access(filename,0)==0);
} 如还有疑问,请追加!
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式