记录键盘,用到的是HOOK技术,也就是常听到的挂钩技术。如果想要捕获键盘鼠标,去查查WH_JOURNALPLAYBACK和WH_JOURNALRECORD挂钩类型的用法。
当然,这些是要做为全局HOOK的,所以同时你也要具备编写DLL的基础。
至于你说的,要在最小化时,任务栏和状态栏里没有图标,你去查查SetWindowLong函数。网上很多。
只要肯动手,实现起来不会太难的!祝楼主好运!
键控程序简单事例:#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=0i<blefti++)
printf(" ")
for(i=0i<widthi++)
{ printf("=")
}
for(i=0i<heighti++)
{ gotoxy(bleft,i)
printf("!")
}
for(i=0i<heighti++)
{ gotoxy(width+bleft,i)
printf("!")
}
for(i=1i<widthi++)
{ 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=0i<shili.yvi++)
{
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=0i<shili.yvi++)
{
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=0i<shili.xvi++)
{
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=0i<shili.xvi++)
{
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)
} 如还有疑问,请追加!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)