Author Topic: Re: MouseInput  (Read 558 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: MouseInput
« on: April 25, 2020, 09:12:42 pm »
Looks like you need to call the MouseUpdate SUB.  Also, in the SUB you will need to call the _MOUSEINPUT function again in the WHILE:WEND loops to get changed mouse data. Like this..

Code: QB64: [Select]
  1. TYPE TypeMouse
  2.     image AS LONG
  3.  
  4.     mb AS INTEGER
  5.     ms AS INTEGER
  6.  
  7.     mx AS INTEGER
  8.     my AS INTEGER
  9.  
  10. DIM SHARED Rat AS TypeMouse
  11.  
  12.  
  13. WHILE NOT Done
  14.     MouseUpdate
  15.     IF Rat.mb > 0 THEN
  16.         PRINT Rat.mb, Rat.mx; Rat.my
  17.     END IF
  18.  
  19.     _LIMIT 60
  20.  
  21. SUB MouseUpdate
  22.         Rat.mx = _MOUSEX
  23.         Rat.my = _MOUSEY
  24.  
  25.         IF _MOUSEBUTTON(1) THEN
  26.             Rat.mb = 1
  27.             WHILE _MOUSEBUTTON(1): n = _MOUSEINPUT: WEND
  28.         END IF
  29.  
  30.         IF _MOUSEBUTTON(2) THEN
  31.             Rat.mb = 2
  32.             WHILE _MOUSEBUTTON(2): n = _MOUSEINPUT: WEND
  33.         END IF
  34.  
  35.         IF _MOUSEBUTTON(3) THEN
  36.             Rat.mb = 3
  37.             WHILE _MOUSEBUTTON(3): n = _MOUSEINPUT: WEND
  38.         END IF
  39.     END IF
  40.  
« Last Edit: April 25, 2020, 09:16:31 pm by Dav »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: MouseInput
« Reply #1 on: April 25, 2020, 09:23:50 pm »
Yep, that's why I'm against the legalization of weed.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: MouseInput
« Reply #2 on: April 25, 2020, 09:46:46 pm »
        IF _MOUSEBUTTON(1) THEN
            Rat.mb = 1
            WHILE _MOUSEBUTTON(1): n = _MOUSEINPUT: WEND
        END IF


Note: The above will generate a pause in your program and stop execution until the mouse button is released.  Press it down, hold it, and your program locks up until you release it.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: MouseInput
« Reply #3 on: April 25, 2020, 09:54:44 pm »
  IF _MOUSEBUTTON(1) THEN Rat.mButton = 1
  IF _MOUSEBUTTON(2) THEN Rat.mButton = 2
  IF _MOUSEBUTTON(3) THEN Rat.mButton = 3
  IF Rat.mButton THEN
      WHILE _MOUSEBUTTON(Rat.mButton): Rat.mInput = _MOUSEINPUT: WEND
  END IF
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: MouseInput
« Reply #4 on: April 25, 2020, 10:07:13 pm »
I can sympathize. I've had days I've looked for my glasses, but I was already wearing them. That's scary. I'd try braille,  which might be okay for computing, but not so much for commuting.  I don't think I could keep my sanity driving over all those damn bumps in the road!

Pete

 - Yeah, I know. Now who's smoking something now?
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: MouseInput
« Reply #5 on: April 26, 2020, 12:00:14 am »
Now if only I can figure out why it works in a simple program but in my game it fails successfully at detecting ANY mouse button presses.  Jinkies!

Try it again in your game, but eliminate the _LIMIT statement. Depending how it is used, _LIMIT can cause a program to miss a mouse click. It may not be the problem in your case, but it's worth a shot.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Marked as best answer by on May 03, 2020, 06:32:43 pm

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: MouseInput
« Reply #6 on: April 26, 2020, 05:40:10 pm »
I tried posting earlier but it was lost,...forever lost! ;)

Anyway, here's a slightly updated thing that I have been working on, that is based largely upon Luke's mouse input article.

Code: QB64: [Select]
  1. '// This method of mouse polling reliably captures mousebutton clicks
  2. '// as single events. It can be done on mouse down or mouse release
  3. TYPE mousestuff
  4.     b AS INTEGER
  5.     s AS STRING * 4
  6.     x AS INTEGER
  7.     y AS INTEGER
  8.  
  9. DIM rat AS mousestuff
  10.  
  11.         'Is the button still in the same position?
  12.         IF _MOUSEBUTTON(1) = mouse_down AND _MOUSEBUTTON(2) = mouse2_down THEN
  13.             DO WHILE _MOUSEINPUT
  14.                 m1% = _MOUSEBUTTON(1): m2% = _MOUSEBUTTON(2)
  15.                 IF _MOUSEBUTTON(1) <> mouse_down AND m1% THEN 'left click
  16.                     rat.x = _MOUSEX: rat.y = _MOUSEY: rat.b = 1: rat.s = "down": Showchange rat
  17.                     EXIT DO 'Process through the queue until the button changes state
  18.                 END IF
  19.                 IF _MOUSEBUTTON(1) <> mouse_down AND NOT m1% THEN 'left release
  20.                     rat.x = _MOUSEX: rat.y = _MOUSEY: rat.b = 1: rat.s = "up": Showchange rat
  21.                     EXIT DO
  22.                 END IF
  23.                 IF _MOUSEBUTTON(2) <> mouse2_down AND m2% THEN 'right click
  24.                     rat.x = _MOUSEX: rat.y = _MOUSEY: rat.b = 2: rat.s = "down": Showchange rat
  25.                     EXIT DO
  26.                 END IF
  27.                 IF _MOUSEBUTTON(2) <> mouse2_down AND NOT m2% THEN 'right release
  28.                     rat.x = _MOUSEX: rat.y = _MOUSEY: rat.b = 2: rat.s = "up": Showchange rat
  29.                     EXIT DO
  30.                 END IF
  31.             LOOP
  32.         END IF
  33.         mouse_down = _MOUSEBUTTON(1)
  34.         mouse2_down = _MOUSEBUTTON(2)
  35.         'Do mouse processing here
  36.     END IF
  37.     'Do other stuff
  38.     _LIMIT 30
  39.  
  40. SUB Showchange (var AS mousestuff)
  41.  
  42.     PRINT var.x, var.y, "button:"; var.b, var.s
  43.  
  44.