Author Topic: Mouse Event Test  (Read 2723 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Mouse Event Test
« on: May 17, 2021, 12:49:27 pm »
This might be interesting way to go with Mouse Button clicks?
Code: QB64: [Select]
  1. _Title "Mouse Event test" 'b+ 2021-05-17
  2.  
  3. Dim Shared mx, my, mb1DownX, mb1DownY, mb1UpX, mb1UpY, oldmb1
  4.  
  5. t1 = _FreeTimer 'get a timer number from _FREETIMER ONLY!
  6. On Timer(t1, .05) PollMouse
  7. Timer(t1) On
  8.  
  9. ' signal no button locations registered yet
  10. mb1DownX = -1
  11. mb1DownY = -1
  12. mb1UpX = -1
  13. mb1UpY = -1
  14.  
  15.     Cls
  16.     Print "         Mouse location at:"; mx; ","; my
  17.     Print "  Status Left Button Down: "; oldmb1
  18.     Print "First Mouse Button Down at:"; mb1DownX; ","; mb1DownY
  19.     Print "   Last Mouse Button Up at:"; mb1UpX; ","; mb1UpY
  20.     _Display
  21. Timer(t1) Free 'release timer
  22.  
  23. Sub PollMouse ' catch locations of mouse button 1 down and up
  24.     mx = _MouseX: my = _MouseY: mb1 = _MouseButton(1)
  25.     If mb1 And oldmb1 = 0 Then
  26.         mb1DownX = mx
  27.         mb1DownY = my
  28.         'mb1UpX = 0
  29.         'mb1UpY = 0
  30.     End If
  31.     If mb1 = 0 And oldmb1 Then
  32.         mb1UpX = mx
  33.         mb1UpY = my
  34.         'mb1DownX = 0
  35.         'mb1DownY = 0
  36.     End If
  37.     oldmb1 = mb1
  38.  
  39.  

Always wanted to try something like this.

BTW look at the example for On Timer Event, it is about mouse which I used to start this code test.

If MB1 then mb1DownX and mb1DownY are latest first down at locations.
If MB1 = 0 then mb1UpX, mb1UpY was location of last release of mouse button 1 which you can clear (set -1) when you have handled the Click.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Mouse Event Test
« Reply #1 on: May 17, 2021, 04:06:14 pm »
Cool... oh... and 'my' version is _rgb32(0,128,255)... Moo Ha Ha...
 
Logic is the beginning of wisdom.