不必调用api了,delphi已经替你搞定了 form delphi helpShiftState indicates the state of the Alt, Ctrl, and Shift keys and the mouse buttons.UnitClassestype TShiftState = set of (ssShift, ssAlt, ssCtrl, ssLeft, ssRight, ssMiddle, ssDouble);DescriptionThe TShiftState type is used by key-event and mouse-event handlers to determine the state of the Alt, Ctrl, and Shift keys and the state of the mouse buttons when the event occurs. It is a set of flags that indicate the following:Value MeaningssShift The Shift key is held down. ssAlt The Alt key is held down. ssCtrl The Ctrl key is held down. ssLeft The left mouse button is held down. ssRight The right mouse button is held down. ssMiddle The middle mouse button is held down. ssDouble The mouse was double-clicked.明白了吧, if ssShift then showmessage('shift is down');
要更底层的,调用GetKeyboardState()API吧。
直接用Key的值不好吗?
int vKey // virtual-key code
);
WM_SYSKEYDOWN,WM_SYSKEYUP.
从消息的WPARAM和LPARAM可以判断键值.
form delphi helpShiftState indicates the state of the Alt, Ctrl, and Shift keys and the mouse buttons.UnitClassestype TShiftState = set of (ssShift, ssAlt, ssCtrl, ssLeft, ssRight, ssMiddle, ssDouble);DescriptionThe TShiftState type is used by key-event and mouse-event handlers to determine the state of the Alt, Ctrl, and Shift keys and the state of the mouse buttons when the event occurs. It is a set of flags that indicate the following:Value MeaningssShift The Shift key is held down.
ssAlt The Alt key is held down.
ssCtrl The Ctrl key is held down.
ssLeft The left mouse button is held down.
ssRight The right mouse button is held down.
ssMiddle The middle mouse button is held down.
ssDouble The mouse was double-clicked.明白了吧,
if ssShift then showmessage('shift is down');