Author Topic: Mouse Controls  (Read 2157 times)

0 Members and 1 Guest are viewing this topic.

Offline Taylorover9001

  • Newbie
  • Posts: 6
    • View Profile
Mouse Controls
« on: May 16, 2021, 09:06:10 pm »
Something I've never understood is, why is stuff related to the mouse so janky? With INKEY$ and _KEYDOWN() for example, they just work. If a key is pressed while INKEY$ or _KEYDOWN() are being invoked, they will report it to you accordingly. But with all the mouse commands, such as _MOUSEBUTTON(), why don't they work in the same sort of way? Why do I need to call _MOUSEINPUT for any of the other mouse commands to work at all? As a result, getting mouse controls to work is always much harder than it really should be. I can and have gotten mouse controls to work in two different programs, but in both cases it took me awhile to do, and making changes can easily cause it to stop working.
« Last Edit: May 16, 2021, 09:10:47 pm by Taylorover9001 »

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Mouse Controls
« Reply #1 on: May 16, 2021, 09:48:47 pm »
"Janky" needs a bit more description. Although I agree that mouse control can be a challenge. Mouse polling is very, very fast, and I've often had to resort to the quick and dirty expedient of _DELAY .2 after a mouse button click to help keep things from going wrong. It's really just the nature of the beast. If it were otherwise, I suspect that a mouse would not be suitable for fast action games and such.

As an example:
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(600, 600, 32)
  2. c& = &HFFFF0000
  3. d& = &HFF0000FF
  4.  
  5.     CLS , c&
  6.     IF _MOUSEBUTTON(1) THEN SWAP c&, d&: _DELAY .2
  7.     _LIMIT 50
  8.     _DISPLAY
  9.  

If you comment out the delay, reliable left click color change becomes quite a challenge.

Not wishing to reinvent the wheel, I've taken to using Steve's MBS function, which works quite well for a lot of applications that I do.

https://www.qb64.org/forum/index.php?topic=3380.msg126835#msg126835

P.S. There are times that _KEYDOWN can be a challenge too.
« Last Edit: May 16, 2021, 09:50:50 pm by OldMoses »

Offline 191Brian

  • Newbie
  • Posts: 91
    • View Profile
    • My Itch page
Re: Mouse Controls
« Reply #2 on: May 17, 2021, 06:33:33 am »
Interesting I have found mouse control works quite well, the only issue I have seen like OldMoses is the need to add a short delay after actioning a click even to avoid duplicating the action.
What particular issues have you had?
Brian ...

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Mouse Controls
« Reply #3 on: May 17, 2021, 10:14:20 am »
I may be way off base on this, and if so, the developers can smack me in the head.

Mouse operations are the domain of the OS interrupt system, and QB64 has to play nice and not supplant that system, or bad coding could seriously crash it. _MOUSEINPUT is QB64's way of going to the OS, with cap clutched to its breast and saying, "Please sir, may I have some more..."

Whereupon, the OS is notified, and it can determine if the resources are available before granting the request.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mouse Controls
« Reply #4 on: May 17, 2021, 11:36:37 am »
I may be way off base on this, and if so, the developers can smack me in the head.

Mouse operations are the domain of the OS interrupt system, and QB64 has to play nice and not supplant that system, or bad coding could seriously crash it. _MOUSEINPUT is QB64's way of going to the OS, with cap clutched to its breast and saying, "Please sir, may I have some more..."

Whereupon, the OS is notified, and it can determine if the resources are available before granting the request.

It's the same hardware/OS relation for keypress as for mouse but Mousebutton() works like _KEYDOWN there is no equivalent in mouse for a button press and likewise no equivalent for mouse as _KeyClear.