?? key_scan.txt
字號:
#include"dos.h"
char key_state[128], key_pressed[128];
/*其中key_state[128]用來表示鍵的當前狀態,key_pressed[128]里保存的值表示哪些鍵被按下,值1表示按下,0表示放開。
*/
void interrupt far (*OldInt9Handler) ();
/*保存好原來的鍵盤中斷程序地址,以便在程序運行結束后恢復它*/
/*新的鍵盤中斷程序*/
void far interrupt NewInt9 (void)
{
char ScanCode,temp;
ScanCode = inportb (0x60);
temp = inportb (0x61);
outportb (0x61, temp | 0x80);
outportb (0x61, temp & 0x7f);
if (ScanCode & 0x80) {
ScanCode &= 0x7f;
key_state[ScanCode] = 0;
}
else {
key_state[ScanCode] = 1;
key_pressed[ScanCode] = 1;
}
outportb (0x20, 0x20);
}
/*安裝新的鍵盤中斷程序的函數*/
void InstallKeyboard (void)
{
int i;
for (i = 0; i < 128; i++)
key_state[i] = key_pressed[i] = 0;
OldInt9Handler = getvect (9);
setvect (9, NewInt9);
}
/*恢復舊的鍵盤中斷程序的函數*/
void ShutDownKeyboard (void)
{
setvect (9, OldInt9Handler);
}
/*讀取按鍵狀態的函數*/
int GetKey (int ScanCode)
{
int res;
res = key_state[ScanCode] | key_pressed[ScanCode];
key_pressed[ScanCode] = 0;
return res;
}
main ()
{
int i,press;
InstallKeyboard ();
while (GetKey (1)==0){ /*按ESC退出*/
press = 0;
for (i = 0; i < 128; i++)
if (GetKey (i)) {
press = 1;
printf ("%4d",i);
}
if (press)
printf ("\n");
else
printf ("\nNokey!\n");
}
ShutDownKeyboard ();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -