Delphi: How can I check if any mouse buttons are pressed - OUTSIDE of a mouse event?

眉间皱痕 提交于 2019-12-10 17:05:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!