Lazarus

Programming => LCL => Topic started by: simsee on December 10, 2016, 01:22:25 pm

Title: Mouse Button State
Post by: simsee on December 10, 2016, 01:22:25 pm
In a GUI context, inside an event handler procedure of a TCustomControl component, I should know the state of mouse buttons. I know that Mouse.CursorPos allows to get the position and that mouse unit of RTL don't work in graphic mode. I can't use classic eventi as OnClick, OnMouseUp, OnMouseDown because I'm already inside another event handler procedure. So, how can I do? Thanks!
Title: Re: Mouse Button State
Post by: Leledumbo on December 10, 2016, 03:10:17 pm
Create a variable maintaining the mouse state yourself (set, boolean array, whatever, you choose). Inside the "classic" events, mark corresponding states in the variable. In another event, check them.
Title: Re: Mouse Button State
Post by: simsee on December 10, 2016, 03:30:55 pm
I used a global boolean variable as a flag, that is set to True by OnMouseDown event handler and to False by OnMouseUp. I asked to the forum because I did not know if there were better solutions. Thanks again!
Title: Re: Mouse Button State
Post by: Blaazen on December 10, 2016, 06:18:33 pm
The same way you call Mouse.CursorPos you can call function GetKeyShiftState (unit Controls) and test if mouse buttons are pushed (ssLeft, ssMiddle, ssRight).
Title: Re: Mouse Button State
Post by: simsee on December 10, 2016, 08:17:59 pm
Thanks Blaazen. I looked at this unit, but I have not noticed this function, which unfortunately is not documented ...
TinyPortal © 2005-2018