问题
I have a TDrawGrid and want to handle clicking on a cell and scrolling through cells with the mouse wheel slightly differently: When scrolling with the mouse wheel, the view shall center on the selected cell, when simply clicking on a cell, the view shall not move (because that'd be confusing).
Scrolling with the mouse wheel fires the OnSelectCell
event. Clicking on a cell FIRST fires OnSelectCell
, followed by OnMouseDown
. So I need to figure out if OnSelectCell
was triggered by a mouse click. Easiest way to do (that I can think of) would be to check the current mouse-button state.
OnSelectCell
doesn't come with any TMouseButton
or TShiftState
parameter. So how can I query the mouse-button state?
回答1:
Use GetKeyState
passing VK_LBUTTON
to identify the primary mouse button. If the return value is negative, the button was down when the system generated the input message that led to the OnSelectCell
event being fired.
来源:https://stackoverflow.com/questions/25681543/delphi-how-can-i-check-if-any-mouse-buttons-are-pressed-outside-of-a-mouse-ev