Author Topic: Mouse input lag  (Read 8409 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Mouse input lag
« Reply #15 on: October 21, 2021, 03:10:29 pm »
Can I help it that I speak with authority? Not like some little whelp.

I have tried it as

DO:LOOP WHILE _MOUSEINPUT

But that tended to cause issues. Can't remember just what it did now though.

I vaguely remember issues with either that, or some other similar method. These days, I just stick to using WHILE:WEND.

Pete

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

Offline johannhowitzer

  • Forum Regular
  • Posts: 118
    • View Profile
Re: Mouse input lag
« Reply #16 on: October 22, 2021, 05:09:41 am »
Code: QB64: [Select]
  1. sub update_inputs
  2.  
  3. call detect_devices
  4.  
  5. if dev_mouse = false then exit sub
  6.  
  7. dim mb(3)
  8. for b = 1 to 3
  9.    mb(b) = mouse_press(b)
  10.  
  11. mouse_change = false
  12. do while mouseinput <> false and mouse_change = false
  13.    mx = mousex
  14.    my = mousey
  15.    for b = 1 to 3
  16.       mb(b) = mousebutton(b)
  17.       if mb(b) <> mouse_press(b) then mouse_change = true
  18.    next b
  19.  
  20. for b = 1 to 3
  21.    mouse_hold(b) = mouse_press(b)
  22.    mouse_press(b) = mb(b)
  23.  
  24.    if mouse_press(b) = true and mouse_hold(b) = false then
  25.       mouse_press_x(b) = mx ' Store position mouse button was pressed
  26.       mouse_press_y(b) = my
  27.    elseif mouse_press(b) = false and mouse_hold(b) = true then
  28.       mouse_release_x(b) = mx ' Store position mouse button was released
  29.       mouse_release_y(b) = my
  30.    end if
  31.  
  32.  

After reading up on all this, here's the changes I made to the routine.  As I drain mouseinput, I stop it short whenever there's a change in one of the three button states, this way it keeps up, even in limit 60, but it also doesn't miss any clicks - which I read was a concern.  This appears to have no issues at all.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Mouse input lag
« Reply #17 on: October 22, 2021, 05:43:02 am »
The only clicks you really have to worry about missing are your scroll wheel events.  They update and clear almost instantly, so you need to track them inside your WHILE:WEND loop, but regular left/right mouse input should never be an issue for you.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: Mouse input lag
« Reply #18 on: October 22, 2021, 07:05:06 am »
To demonstrate precisely why a simple Do: Loop While _Mouseinput is insufficient in some cases, consider the following two programs:
Code: [Select]
'Program A
$noprefix
Do
    Do: Loop While MouseInput
    If MouseButton(1) Then
        i = i + 1
        Print "Click"; i; "processing...";
        Delay 0.5
        Print "Done"
    End If
    Limit 30
Loop
Code: [Select]
'Program B
$noprefix
Do
    If MouseInput Then
        If MouseButton(1) = mouse_down Then 'Is the button still in the same position?
            Do While MouseInput
                If MouseButton(1) <> mouse_down Then Exit Do 'Process through the queue until the button changes state
            Loop
        End If
        mouse_down = MouseButton(1)
        'Do mouse processing here
        If mouse_down Then
            i = i + 1
            Print "Click"; i; "processing...";
            Delay 0.5
            Print "Done"
        End If
    End If
    Limit 30
Loop

In both cases, the intention is to capture each mouse click and perform some "processing" on it. Here our "processing" is just a delay to simulate some actual code. Run each program and do some clicks. You should see a new message printed for each click. Now try a double click (two clicks in rapid succession). Assuming you're reasonably quick, you'll notice that program A will only register the first click - any clicks done during the "processing" time are ignored. Program B avoids this by scanning through the input buffer to see if there were any click events that need to be processed.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Mouse input lag
« Reply #19 on: October 22, 2021, 11:20:51 am »
@luke makes a good point about more advanced mouse usage such as double-clicks, and I'll add drag in that mix. @johannhowitzer  Personally, I strive for flow through code, so all my routines are free of _DELAY statements and continuously cycle back to the main. In the code I posted, you will notice the effects like double-click and drag are obtained by tracking time and mouse button states (pressed and released.) Frankly, I'd wish you'd change your code to the WHILE:WEND model, as it would be easier to help you implement these other features, including _MOUSEWHEEL, as @SMcNeill posted. Of course if you have all that you will ever need for this and other routines cooked into the code you posted, that's fine. I rank creativity over dogma most of the time.

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

Offline johannhowitzer

  • Forum Regular
  • Posts: 118
    • View Profile
Re: Mouse input lag
« Reply #20 on: October 22, 2021, 03:23:56 pm »
I didn't put double click tracking in there yet, but my code does support dragging, as it not only tracks press and release, but where each happened.  This is partly so I can make sure both happened over the same hotspot - so if you click a button, hold, then release the mouse while not over the button, it won't activate it.

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Mouse input lag
« Reply #21 on: October 27, 2021, 10:15:08 am »
I'm thinking this thread may have come to an end as interesting and helpful as it was.... but felt I needed to defend myself (ie @bplus .. on/off). Mark is correct, typically a light goes ON but the interchangeable use of ON/OFF is rampant in the English language .. ie "the gun when off" doesn't mean it was turned off and inactive, it means it was turned on and very active... same with the horse races "..and their off" doesn't mean the horses are off the track, it does mean they are very much on the race track and running.

And here's one which is very confusing but logical "..and the Dimster is Off, ON another of his rants."

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mouse input lag
« Reply #22 on: October 27, 2021, 10:56:01 am »
I'm thinking this thread may have come to an end as interesting and helpful as it was.... but felt I needed to defend myself (ie @bplus .. on/off). Mark is correct, typically a light goes ON but the interchangeable use of ON/OFF is rampant in the English language .. ie "the gun when off" doesn't mean it was turned off and inactive, it means it was turned on and very active... same with the horse races "..and their off" doesn't mean the horses are off the track, it does mean they are very much on the race track and running.

And here's one which is very confusing but logical "..and the Dimster is Off, ON another of his rants."

Always nice to get a peek into how another thinks, very nice logical explanation, thankyou I am smiling.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Mouse input lag
« Reply #23 on: October 27, 2021, 04:35:20 pm »
I find this conversation to be on the whole, OFF topic.

The
.. ie "the gun when off" doesn't mean it was turned off and inactive, it means it was turned on and very active... same with the horse races "..and their off" doesn't mean the horses are off the track, it does mean they are very much on the race track and running.

 "the gun when off" Huh? How can the gun go off "when" the gun is off? Oh well, maybe a better question for that idiot actor, Alex Baldwin.

Pete

In Soviet Russia, to stay on top, you have to stay off bottom of things.
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Mouse input lag
« Reply #24 on: October 27, 2021, 07:29:35 pm »
Mark is correct, typically a light goes ON but the interchangeable use of ON/OFF is rampant in the English language .. ie "the gun when off" doesn't mean it was turned off and inactive, it means it was turned on and very active... same with the horse races "..and their off" doesn't mean the horses are off the track, it does mean they are very much on the race track and running.

And here's one which is very confusing but logical "..and the Dimster is Off, ON another of his rants."

side note:
 When a gun discharges it is off, because it is safe at that point. Once a new round is chambered the gun is now "charged" or ON and is again very dangerous. as with a light bulb, when the line is unloaded(off[aka no power]) it is safe to change, how ever when the line is loaded(ON [aka has power]) you can fry yourself!

I would like to think of it as "Dimster is Off, ON another journey seeking enlightenment!"
Granted after becoming radioactive I only have a half-life!

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Mouse input lag
« Reply #25 on: October 28, 2021, 10:24:08 am »
You're right @Pete, that should have read "went off" and not " when". Not sure how I missed that typo. Off my game I guess.
And @Cobalt, when it comes to the On and Off of light switches, I'm starting to hear the phrase "open/closed" with electricians, rather than On/Off. But I do agree with you, @blus called me on that use of On/Off for the proverbial enlightening light bulb.

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Mouse input lag
« Reply #26 on: October 28, 2021, 11:14:06 am »
@Cobalt ... just to elaborate on that light switch "open/closed". I recently had an electrician install a water pump for me. Because there would be more people switching that switch I asked him to label the on/off positions. He labelled "pump on/ pump off". I suggested he could have just labelled on/off. He said a switch is like a circuit breaker which opens and closes but the object at the end of the line of the power will be either on or off. That phase "switched on" should in fact be "switched open"..

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mouse input lag
« Reply #27 on: October 28, 2021, 12:19:43 pm »
You're right @Pete, that should have read "went off" and not " when". Not sure how I missed that typo. Off my game I guess.
And @Cobalt, when it comes to the On and Off of light switches, I'm starting to hear the phrase "open/closed" with electricians, rather than On/Off. But I do agree with you, @blus called me on that use of On/Off for the proverbial enlightening light bulb.

Oh ha! I am blus now, I like it! I type that allot, @Dimster I guess you are On your game now by being Off a bit ;-))

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Mouse input lag
« Reply #28 on: October 28, 2021, 12:56:19 pm »
Freudian slip ... always felt it should be Aplus.