Board logo

標題: [Delphi] Virtual key 的使用 [打印本頁]

作者: admin    時間: 2010-10-4 22:16     標題: [Delphi] Virtual key 的使用

Symbolic constant nameValue (hex)Mouse or keyboard equivalents
VK_LBUTTON01Left mouse button
VK_RBUTTON02Right mouse button
VK_CANCEL03Control-break processing
VK_MBUTTON04Middle mouse button (three-button mouse)
VK_XBUTTON105Windows 2000/XP/2003/Vista/2008/7: X1 mouse button
VK_XBUTTON206Windows 2000/XP/2003/Vista/2008/7: X2 mouse button
-07Undefined
VK_BACK08BACKSPACE key
VK_TAB09TAB key
-0A-0BReserved
VK_CLEAR0CCLEAR key
VK_RETURN0DENTER key
-0E-0FUndefined
VK_SHIFT10SHIFT key
VK_CONTROL11CTRL key
VK_MENU12ALT key
VK_PAUSE13PAUSE key
VK_CAPITAL14CAPS LOCK key
VK_KANA15Input Method Editor (IME) Kana mode
VK_HANGUEL15IME Hanguel mode (maintained for compatibility; use VK_HANGUL)
VK_HANGUL15IME Hangul mode
-16Undefined
VK_JUNJA17IME Junja mode
VK_FINAL18IME final mode
VK_HANJA19IME Hanja mode
VK_KANJI19IME Kanji mode
-1AUndefined
VK_ESCAPE1BESC key
VK_CONVERT1CIME convert (Reserved for Kanji systems)
VK_NONCONVERT1DIME nonconvert (Reserved for Kanji systems)
VK_ACCEPT1EIME accept (Reserved for Kanji systems)
VK_MODECHANGE1FIME mode change request (Reserved for Kanji systems)
VK_SPACE20SPACEBAR
VK_PRIOR21PAGE UP key
VK_NEXT22PAGE DOWN key
VK_END23END key
VK_HOME24HOME key
VK_LEFT25LEFT ARROW key
VK_UP26UP ARROW key
VK_RIGHT27RIGHT ARROW key
VK_DOWN28DOWN ARROW key
VK_SELECT29SELECT key
VK_PRINT2APRINT key
VK_EXECUTE2BEXECUTE key
VK_SNAPSHOT2CPRINT SCREEN key for Windows 3.0 and later
VK_INSERT2DINS key
VK_DELETE2EDEL key
VK_HELP2FHELP key
VK_0300 key
VK_1311 key
VK_2322 key
VK_3333 key
VK_4344 key
VK_5355 key
VK_6366 key
VK_7377 key
VK_8388 key
VK_9399 key
-3A-40Undefined
VK_A41A key
VK_B42B key
VK_C43C key
VK_D44D key
VK_E45E key
VK_F46F key
VK_G47G key
VK_H48H key
VK_I49I key
VK_J4AJ key
VK_K4BK key
VK_L4CL key
VK_M4DM key
VK_N4EN key
VK_O4FO key
VK_P50P key
VK_Q51Q key
VK_R52R key
VK_S53S key
VK_T54T key
VK_U55U key
VK_V56V key
VK_W57W key
VK_X58X key
VK_Y59Y key
VK_Z5AZ key
VK_LWIN5BLeft Windows key (Microsoft Natural Keyboard)
VK_RWIN5CRight Windows key (Microsoft Natural Keyboard)
VK_APPS5DApplications key (Microsoft Natural Keyboard)
-5EReserved
VK_SLEEP5FComputer Sleep key
VK_NUMPAD060Numeric keypad 0 key
VK_NUMPAD161Numeric keypad 1 key
VK_NUMPAD262Numeric keypad 2 key
VK_NUMPAD363Numeric keypad 3 key
VK_NUMPAD464Numeric keypad 4 key
VK_NUMPAD565Numeric keypad 5 key
VK_NUMPAD666Numeric keypad 6 key
VK_NUMPAD767Numeric keypad 7 key
VK_NUMPAD868Numeric keypad 8 key
VK_NUMPAD969Numeric keypad 9 key
VK_MULTIPLY6AMultiply key
VK_ADD6BAdd key
VK_SEPARATOR6CSeparator key
VK_SUBTRACT6DSubtract key
VK_DECIMAL6EDecimal key
VK_DIVIDE6FDivide key
VK_F170F1 key
VK_F271F2 key
VK_F372F3 key
VK_F473F4 key
VK_F574F5 key
VK_F675F6 key
VK_F776F7 key
VK_F877F8 key
VK_F978F9 key
VK_F1079F10 key
VK_F117AF11 key
VK_F127BF12 key
VK_F137CF13 key
VK_F147DF14 key
VK_F157EF15 key
VK_F167FF16 key
VK_F1780HF17 key
VK_F1881HF18 key
VK_F1982HF19 key
VK_F2083HF20 key
VK_F2184HF21 key
VK_F2285HF22 key
VK_F2386HF23 key
VK_F2487HF24 key
-88-8FUnassigned
VK_NUMLOCK90NUM LOCK key
VK_SCROLL91SCROLL LOCK key
VK_OEM_NEC_EQUAL92NEC PC-9800 kbd definitions: '=' key on numpad
VK_OEM_FJ_JISHO92Fujitsu/OASYS kbd definitions: 'Dictionary' key
VK_OEM_FJ_MASSHOU93Fujitsu/OASYS kbd definitions: 'Unregister word' key
VK_OEM_FJ_TOUROKU94Fujitsu/OASYS kbd definitions: 'Register word' key
VK_OEM_FJ_LOYA95Fujitsu/OASYS kbd definitions: 'Left OYAYUBI' key
VK_OEM_FJ_ROYA96Fujitsu/OASYS kbd definitions: 'Right OYAYUBI' key
-97-9FUnassigned
VK_LSHIFTA0Left SHIFT key
VK_RSHIFTA1Right SHIFT key
VK_LCONTROLA2Left CONTROL key
VK_RCONTROLA3Right CONTROL key
VK_LMENUA4Left MENU key
VK_RMENUA5Right MENU key
VK_BROWSER_BACKA6Windows 2000/XP/2003/Vista/2008/7: Browser Back key
VK_BROWSER_FORWARDA7Windows 2000/XP/2003/Vista/2008/7: Browser Forward key
VK_BROWSER_REFRESHA8Windows 2000/XP/2003/Vista/2008/7: Browser Refresh key
VK_BROWSER_STOPA9Windows 2000/XP/2003/Vista/2008/7: Browser Stop key
VK_BROWSER_SEARCHAAWindows 2000/XP/2003/Vista/2008/7: Browser Search key
VK_BROWSER_FAVORITESABWindows 2000/XP/2003/Vista/2008/7: Browser Favorites key
VK_BROWSER_HOMEACWindows 2000/XP/2003/Vista/2008/7: Browser Start and Home key
VK_VOLUME_MUTEADWindows 2000/XP/2003/Vista/2008/7: Volume Mute key
VK_VOLUME_DOWNAEWindows 2000/XP/2003/Vista/2008/7: Volume Down key
VK_VOLUME_UPAFWindows 2000/XP/2003/Vista/2008/7: Volume Up key
VK_MEDIA_NEXT_TRACKB0Windows 2000/XP/2003/Vista/2008/7: Next Track key
VK_MEDIA_PREV_TRACKB1Windows 2000/XP/2003/Vista/2008/7: Previous Track key
VK_MEDIA_STOPB2Windows 2000/XP/2003/Vista/2008/7: Stop Media key
VK_MEDIA_PLAY_PAUSEB3Windows 2000/XP/2003/Vista/2008/7: Play/Pause Media key
VK_LAUNCH_MAILB4Windows 2000/XP/2003/Vista/2008/7: Start Mail key
VK_LAUNCH_MEDIA_SELECTB5Windows 2000/XP/2003/Vista/2008/7: Select Media key
VK_LAUNCH_APP1B6Windows 2000/XP/2003/Vista/2008/7: Start Application 1 key
VK_LAUNCH_APP2B7Windows 2000/XP/2003/Vista/2008/7: Start Application 2 key
-B8-B9Reserved
VK_OEM_1BAWindows 2000/XP/2003/Vista/2008/7: For the US standard keyboard, the ';:' key
VK_OEM_PLUSBBWindows 2000/XP/2003/Vista/2008/7: For any country/region, the '+' key
VK_OEM_COMMABCWindows 2000/XP/2003/Vista/2008/7: For any country/region, the ',' key
VK_OEM_MINUSBDWindows 2000/XP/2003/Vista/2008/7: For any country/region, the '-' key
VK_OEM_PERIODBEWindows 2000/XP/2003/Vista/2008/7: For any country/region, the '.' key
VK_OEM_2BFWindows 2000/XP/2003/Vista/2008/7: For the US standard keyboard, the '/?' key
VK_OEM_3C0Windows 2000/XP/2003/Vista/2008/7: For the US standard keyboard, the '`~' key
-C1-D7Reserved
-D8-DAUnassigned
VK_OEM_4DBWindows 2000/XP/2003/Vista/2008/7: For the US standard keyboard, the '[{' key
VK_OEM_5DCWindows 2000/XP/2003/Vista/2008/7: For the US standard keyboard, the '\|' key
VK_OEM_6DDWindows 2000/XP/2003/Vista/2008/7: For the US standard keyboard, the ']}' key
VK_OEM_7DEWindows 2000/XP/2003/Vista/2008/7: For the US standard keyboard, the 'single-quote/double-quote' key
VK_OEM_8DFUsed for miscellaneous characters; it can vary by keyboard.
-E0Reserved
E1OEM specific
VK_OEM_102E2Windows 2000/XP/2003/Vista/2008/7: Either the angle bracket key or the backslash key on the RT 102-key keyboard
-E3-E4OEM specific
VK_PROCESSKEYE5Windows 95/98/Me, Windows NT/2000/XP/2003/Vista/2008/7: IME PROCESS key
-E6OEM specific
VK_PACKETE7Windows 2000/XP/2003/Vista/2008/7: Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT , SendInput , WM_KEYDOWN , and WM_KEYUP
-E8Unassigned
VK_OEM_RESETE9Only used by Nokia.
VK_OEM_JUMPEAOnly used by Nokia.
VK_OEM_PA1EBOnly used by Nokia.
VK_OEM_PA2ECOnly used by Nokia.
VK_OEM_PA3EDOnly used by Nokia.
VK_OEM_WSCTRLEEOnly used by Nokia.
VK_OEM_CUSEL EFOnly used by Nokia.
VK_OEM_ATTN F0Only used by Nokia.
VK_OEM_FINNISH F1Only used by Nokia.
VK_OEM_COPY F2Only used by Nokia.
VK_OEM_AUTO F3Only used by Nokia.
VK_OEM_ENLW F4Only used by Nokia.
VK_OEM_BACKTAB F5Only used by Nokia.
VK_ATTNF6Attn key
VK_CRSELF7CrSel key
VK_EXSELF8ExSel key
VK_EREOFF9Erase EOF key
VK_PLAYFAPlay key
VK_ZOOMFBZoom key
VK_NONAMEFCReserved for future use.
VK_PA1FDPA1 key
VK_OEM_CLEARFEClear key
FFMultimedia keys. See ScanCode keys

作者: admin    時間: 2010-10-23 16:22

要在程式中截取以上所有按鍵 (Virtual key),然後根據所按的鍵做不到動作,你可以在button 中的 button.keyDown 或 button.keyUp 中

當按鍵被按下時 KeyDown event 會被觸發,當按鍵被鬆開時 KeyUp event 會被觸發,當一個 KeyDown 加一個 KeyUp 就會觸發 KeyPress,但截取所有 Virtual key,程式碼不要放在 KeyPress 裡面,因為不是所有 Virtual key都能夠執行,它只會針對某些 Key 做處理,因此請把自己要處理的動作放在 KeyDown 或 KeyUp 裡面。

但如你把程式放在 button.keyDown 或 button.keyUp,由於button 一定放置於一個form 內,而此form 如同時存在其它元件,有些 key 如 Enter 及箭咀移動都會被form 截取做其它處理,沒法傳到 button.keyDown 或 button.keyUp, 例如 Enter 鍵觸發default 元件及箭咀移動按鍵令 focus 在不同元件中走動,因此要做到百份百截取所有 virtual key,其中一個做法是.....


本帖隱藏的內容需要回復才可以瀏覽





歡迎光臨 How2Do (http://forum.how2do.com.hk/) Powered by Discuz! 7.2