Recent

Author Topic: Mouse Button State  (Read 3023 times)

simsee

  • New Member
  • *
  • Posts: 48
Mouse Button State
« 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!

Leledumbo

  • Hero Member
  • *****
  • Posts: 8112
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Mouse Button State
« Reply #1 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.

simsee

  • New Member
  • *
  • Posts: 48
Re: Mouse Button State
« Reply #2 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!

Blaazen

  • Hero Member
  • *****
  • Posts: 2782
  • POKE 54296,15
    • Eye-Candy Controls
Re: Mouse Button State
« Reply #3 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).
Lazarus 2.1.0 r61214:62238 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

simsee

  • New Member
  • *
  • Posts: 48
Re: Mouse Button State
« Reply #4 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 ...