📄 csd_keyprocess.c
字号:
//CSD_KeyProcess.c
//按下 shift 后应亮灯
//按下 shiftCAP 后应亮灯
#define KEY_TOTAL_NUM 36 //键的个数
#define KEY_NUM_DIV8 ( KEY_TOTAL_NUM / 8 ) + 1 //键盘位图的数组下标个数
#define FlgSet 1
#define FlgReset 0
BYTE ScanArrayImage[5]; //={0,0,0,0,0};//第一个键位于ScanArrayImage[0].bit0
//bit0->ShiftLock,bit1->NumLock,bit2->ScrollLock,bit3->ArrowLock,bit4->CapsLock,
//控制键状态值(当ShiftLock位被设定后,处理完一轮键,需要将此位复位)
//键物理序号->控制键/字符键,(字符第一键值(1B)),(附加控制键值(Ctrl/Shift/Alt),第二键属性(上档,数字,保留,光标)(1B)),(第二键索引(1B))
//上档键序号->字符第二键值(1B)
//数字键序号->字符第二键值(1B)
//光标键序号->字符第二键值(1B)
/* 以下为 HID USB 键盘码表
00 Reserved (no event indicated)9
01 Keyboard ErrorRollOver9
02 Keyboard POSTFail9
03 Keyboard ErrorUndefined9
04 Keyboard a and A4
05 Keyboard b and B
06 Keyboard c and C4
07 Keyboard d and D
08 Keyboard e and E
09 Keyboard f and F
0A Keyboard g and G
0B Keyboard h and H
0C Keyboard i and I
0D Keyboard j and J
0E Keyboard k and K
0F Keyboard l and L
10 Keyboard m and M4
11 Keyboard n and N
12 Keyboard o and O4
13 Keyboard p and P4
14 Keyboard q and Q4
15 Keyboard r and R
16 Keyboard s and S4
17 Keyboard t and T
18 Keyboard u and U
19 Keyboard v and V
1A Keyboard w and W4
1B Keyboard x and X4
1C Keyboard y and Y4
1D Keyboard z and Z4
1E Keyboard 1 and !4
1F Keyboard 2 and @4
20 Keyboard 3 and #4
21 Keyboard 4 and $4
22 Keyboard 5 and %4
23 Keyboard 6 and ^4
24 Keyboard 7 and &4
25 Keyboard 8 and *4
26 Keyboard 9 and (4
27 Keyboard 0 and )4
28 Keyboard Return (ENTER)5
29 Keyboard ESCAPE
2A Keyboard DELETE (Backspace)13
2B Keyboard Tab
2C Keyboard Spacebar
2D Keyboard - and (underscore)4
2E Keyboard = and +4
2F Keyboard [ and {4
30 Keyboard ] and }4
31 Keyboard \ and |
32 Keyboard Non-US # and ~2
33 Keyboard ; and :4
34 Keyboard ' and "4
35 Keyboard Grave Accent and Tilde4
36 Keyboard , and <4
37 Keyboard . and >4
38 Keyboard / and ?4
39 Keyboard Caps Lock11
3A Keyboard F1
3B Keyboard F2
3C Keyboard F3
3D Keyboard F4
3E Keyboard F5
3F Keyboard F6
40 Keyboard F7
41 Keyboard F8
42 Keyboard F9
43 Keyboard F10
44 Keyboard F11
45 Keyboard F12
46 Keyboard PrintScreen1
47 Keyboard Scroll Lock11
48 Keyboard Pause1
49 Keyboard Insert1
4A Keyboard Home1
4B Keyboard PageUp1
4C Keyboard Delete Forward1;
4D Keyboard End1
4E Keyboard PageDown1
4F Keyboard RightArrow1
50 Keyboard LeftArrow1
51 Keyboard DownArrow1
52 Keyboard UpArrow1
53 Keypad Num Lock and Clear11
54 Keypad /1
55 Keypad *
56 Keypad -
57 Keypad +
58 Keypad ENTER5
59 Keypad 1 and End
5A Keypad 2 and Down Arrow
5B Keypad 3 and PageDn
5C Keypad 4 and Left Arrow
5D Keypad 5
5E Keypad 6 and Right Arrow
5F Keypad 7 and Home
60 Keypad 8 and Up Arrow
61 Keypad 9 and PageUp
62 Keypad 0 and Insert
63 Keypad . and Delete
64 Keyboard Non-US \ and |3;6
65 Keyboard Application10
*/
//键物理序号->控制键/字符键,(字符第一键值(1B)),(修饰键值(Ctrl/Shift/Alt),第二键属性(上档,数字,保留,光标)(1B)),(第二键索引(1B))
// 1 2 4 8 4 2 1
//附加控制键值(高4位)为向USB送键值时,加入的修饰键定义;
//第二键属性(低4位) 为查附加表索引
//第二键索引 为对应附加表内键值排列索引
const char FirstKeyArray[40][3] =
{
//共定义了34个键
{0x50,0x00,0x00}, //Left Arrow 0 - p4.2
{0x19,0x28,0x0D}, // V ? (0x38) 1 - p5.4
{0x06,0x04,0x09}, // C 9 (0x26) 2 - p3.4
{0x1B,0x04,0x08}, // X 8 (0x25) 3 - p2.4
{0x1D,0x04,0x07}, // Z 7 (0x24) 4 - 0.2
{0xA3,0x00,0x00}, //function key Shift 5 - p5.0
{0x0A,0x04,0x0A}, // G 0 (0x27) 6 - p3.0
{0x09,0x04,0x06}, // F 6 (0x23) 7 - p3.6
{0x07,0x04,0x05}, // D 5 (0x22) 8 - p4.4
{0x16,0x04,0x04}, // S 4 (0x21) 9 - p2.6
{0x04,0x00,0x00}, // A (无 上挡键) 10 - p0.4
{0x2C,0x00,0x00}, // space (无 上挡键) 11 - 5.2
{0x33,0x08,0x0F}, // ; / (0x38) 12 - p5.6
{0x17,0x28,0x0B}, // T ( (0x26) 13 - p3.2
{0x15,0x04,0x03}, // R 3 (0x20) 14 - p4.0
{0x08,0x04,0x02}, // E 2 (0x1F) 15 - p4.6
{0x1A,0x04,0x01}, // W 1 (0x1E) 16 - p0.0
{0x14,0x28,0x0A}, // Q # (0x20) 17 - p0.6
{0x4F,0x00,0x00}, //Right Arrow 18 - p4.3
{0xA5,0x00,0x00}, //function key shift and Cap 19 - p5.1
{0x05,0x28,0x01}, // B | (0x31) 20 - p3.1
{0x11,0x08,0x07}, // N , (0x36) 21 - p2.5
{0x10,0x08,0x06}, // M . (0x37) 22 - p0.3
{0x4C,0x00,0x00}, //Del 23 - p5.3
{0x2A,0x00,0x00}, //BackSpace 24 - p3.3
{0x0B,0x08,0x02}, // H ; (0x33) 25 - p3.7
{0x0D,0x08,0x04}, // J ' (0x34) 26 - p4.5
{0x0E,0x28,0x05}, // K " (0x34) 27 - p2.7
{0x0F,0x28,0x11}, // L ! (0x1E)) 28 - p0.5
{0x28,0x00,0x00}, //CR 29 - p5.5
{0x1F,0x28,0x10}, // % @ (0x22) //需要特殊处理 30 - p5.7
{0x1C,0x28,0x0E}, // Y ) (0x27) 31 - p3.5
{0x18,0x08,0x0C}, // U - (0x2D) 32 - p4.1
{0x0C,0x28,0x03}, // I + (0x2E) 33 - p4.7
{0x12,0x28,0x08}, // O < (0x36) 34 - p0.1
{0x13,0x28,0x09}, // P > (0x37) 35 - p1.7
};
const char ShiftKeyArray[19] = //表 8
{
0x31,//shift+|
0x33,//;
0x2E,//shift+;
0x34,//'
0x34,//shift+"
0x37,//.
0x36,//,
0x36,//shift+<
0x37,//shift+>
0x20,//shift+# (0x0a)
0x26,//shift+( (0x0b)
0x2D,//- (0x0c)
0x38,//shift+? (0x0d)
0x27,//shift+) (0x0e)
0x38,// / (0x0f)
0x22,//shift+% (0x10)
0x1E,//shift+! (0x11)
};
const char NumKeyArray[13] = //表 4
{
0x1E,//1
0x1F,//2
0x20,//3
0x21,//4
0x22,//5
0x23,//6
0x24,//7
0x25,//8
0x26,//9
0x27,//0
};
const char ArrowKeyArray[4] = //表 1
{
0x52,//up arrow
};
struct globle_bit_struct
{
BYTE ShiftLockFlg : 1; //用于表示 是否进入了 上档锁定
BYTE NumLockFlg : 1; //用于表示 是否进入了 数字锁定
BYTE CtrlFlg : 1; //用于表示 是否进入了 Ctrl锁定
BYTE ArrowLockFlg : 1; //用于表示 是否进入了 光标锁定
BYTE CapsLockFlg : 1; //用于表示 是否进入了 大写锁定
//BYTE KeyDownFlg : 1; //键盘按下标志位
} KeyProStatus;
void delay_ms( int MsTimes )
{
int i,j;
for( i=0;i< MsTimes;i++ )
for( j=0;j<100;j++ )
;
}
void BeepDelayXXms( int XXms )
{
Beep_Switch(1); //借用 LED_Shift 作为 Beep 的 API 使用
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -