ESC 退出程序(delphi)
2008-01-25 15:38

分別在FormCreate,FormKeyPress下編寫一句代碼就可以了如下:

procedure TForm1.FormCreate(Sender: TObject);
begin
//這一行沒宣告的話,無法執行定義的功能
keypreview:=true; //可以接收鍵盤操作
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key = #27 then
application.terminate; //關閉程序
if key=VK_F2 then
begin
showmessage('Show F2');
end;

end;

#13 回車
#10換行
#20為空格
鍵盤常用ASCII碼(delphi)
鍵盤常用ASCII碼(delphi) ESC鍵 VK_ESCAPE (27)
回車鍵: VK_RETURN (13)
TAB鍵: VK_TAB (9)
Caps Lock鍵: VK_CAPITAL (20)

Shift 鍵: VK_SHIFT ($10) Ctrl鍵: VK_CONTROL (17) Alt鍵: VK_MENU (18) 空格鍵: VK_SPACE ($20/32) 退格鍵: VK_BACK (8) 左徽標鍵: VK_LWIN (91) 右徽標鍵: VK_LWIN (92) 鼠標右鍵快捷鍵:VK_APPS (93) Insert鍵: VK_INSERT (45) Home鍵: VK_HOME (36) Page Up: VK_PRIOR (33) PageDown: VK_NEXT (34) End鍵: VK_END (35) Delete鍵: VK_DELETE (46) 方向鍵(←): VK_LEFT (37) 方向鍵(↑): VK_UP (38) 方向鍵(→): VK_RIGHT (39) 方向鍵(↓): VK_DOWN (40) F1鍵: VK_F1 (112) F2鍵: VK_F2 (113) F3鍵: VK_F3 (114) F4鍵: VK_F4 (115) F5鍵: VK_F5 (116) F6鍵: VK_F6 (117) F7鍵: VK_F7 (118) F8鍵: VK_F8 (119) F9鍵: VK_F9 (120) F10鍵: VK_F10 (121) F11鍵: VK_F11 (122) F12鍵: VK_F12 (123) Num Lock鍵: VK_NUMLOCK (144) 小鍵盤0: VK_NUMPAD0 (96) 小鍵盤1: VK_NUMPAD0 (97) 小鍵盤2: VK_NUMPAD0 (98) 小鍵盤3: VK_NUMPAD0 (99) 小鍵盤4: VK_NUMPAD0 (100) 小鍵盤5: VK_NUMPAD0 (101) 小鍵盤6: VK_NUMPAD0 (102) 小鍵盤7: VK_NUMPAD0 (103) 小鍵盤8: VK_NUMPAD0 (104) 小鍵盤9: VK_NUMPAD0 (105) 小鍵盤.: VK_DECIMAL (110) 小鍵盤*: VK_MULTIPLY (106) 小鍵盤+: VK_MULTIPLY (107) 小鍵盤-: VK_SUBTRACT (109) 小鍵盤/: VK_DIVIDE (111) Pause Break鍵: VK_PAUSE (19) Scroll Lock鍵: VK_SCROLL (145)
//------------------------------
VK_LBUTTON = 1;
VK_RBUTTON = 2;
VK_CANCEL = 3;
VK_MBUTTON = 4;
VK_BACK = 8;
VK_TAB = 9;
VK_CLEAR = 12;
VK_RETURN = 13;
VK_SHIFT = $10;
VK_CONTROL = 17;
VK_MENU = 18;
VK_PAUSE = 19;
VK_CAPITAL = 20;
VK_ESCAPE = 27;
VK_SPACE = $20;
VK_PRIOR = 33;
VK_NEXT = 34;
VK_END = 35;
VK_HOME = 36;
VK_LEFT = 37;
VK_UP = 38;
VK_RIGHT = 39;
VK_DOWN = 40;
VK_SELECT = 41;
VK_PRINT = 42;
VK_EXECUTE = 43;
VK_SNAPSHOT = 44;
VK_INSERT = 45;
VK_DELETE = 46;
VK_HELP = 47;
{ VK_0 thru VK_9 are the same as ASCII '0' thru '9' ($30 - $39) }
{ VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' ($41 - $5A) }
VK_LWIN = 91;
VK_RWIN = 92;
VK_APPS = 93;
VK_NUMPAD0 = 96;
VK_NUMPAD1 = 97;
VK_NUMPAD2 = 98;
VK_NUMPAD3 = 99;
VK_NUMPAD4 = 100;
VK_NUMPAD5 = 101;
VK_NUMPAD6 = 102;
VK_NUMPAD7 = 103;
VK_NUMPAD8 = 104;
VK_NUMPAD9 = 105;
VK_MULTIPLY = 106;
VK_ADD = 107;
VK_SEPARATOR = 108;
VK_SUBTRACT = 109;
VK_DECIMAL = 110;
VK_DIVIDE = 111;
VK_F1 = 112;
VK_F2 = 113;
VK_F3 = 114;
VK_F4 = 115;
VK_F5 = 116;
VK_F6 = 117;
VK_F7 = 118;
VK_F8 = 119;
VK_F9 = 120;
VK_F10 = 121;
VK_F11 = 122;
VK_F12 = 123;
VK_F13 = 124;
VK_F14 = 125;
VK_F15 = 126;
VK_F16 = 127;
VK_F17 = 128;
VK_F18 = 129;
VK_F19 = 130;
VK_F20 = 131;
VK_F21 = 132;
VK_F22 = 133;
VK_F23 = 134;
VK_F24 = 135;
VK_NUMLOCK = 144;
VK_LSHIFT = 160;
VK_RSHIFT = 161;
VK_LCONTROL = 162;
VK_RCONTROL = 163;
VK_LMENU = 164;
VK_RMENU = 165;
VK_PROCESSKEY = 229;
VK_ATTN = 246;
VK_CRSEL = 247;
VK_EXSEL = 248;
VK_EREOF = 249;
VK_PLAY = 250;
VK_ZOOM = 251;
VK_NONAME = 252;
VK_PA1 = 253;
VK_OEM_CLEAR = 254;

giga0066 發表在 痞客邦 PIXNET 留言(0) 人氣()