Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PolledInput flushes keys/mousebutton on suspend/resume #16

Open
GWRon opened this issue Feb 13, 2018 · 3 comments
Open

PolledInput flushes keys/mousebutton on suspend/resume #16

GWRon opened this issue Feb 13, 2018 · 3 comments

Comments

@GWRon
Copy link
Contributor

GWRon commented Feb 13, 2018

Create a simple graphical window.

SuperStrict
'Framework Brl.Retro
Import Brl.Graphics
Import Brl.GLMax2D
Import Pub.Win32



SetGraphicsDriver GLMax2DDriver()
Graphics 800,600


Function MyHook:Object( id:Int,data:Object,context:Object )
	Local ev:TEvent=TEvent(data)
	If Not ev Return data

	Print "event: "+ev.id +"  data="+ev.data	
End Function
AddHook EmitEventHook,MyHook,Null,0

While Not (KeyHit(KEY_ESCAPE) Or AppTerminate())
 	DrawText "A = "+KeyDown(KEY_A), 0, 200

	Flip
	Cls
Wend

Hold "A" and Alt-Tab (needed, as clicking "somewhere into another window" does not emit suspend-events).
Keep holding "A" and Alt-Tab back into your window.

For BlitzMax "A" is no longer "down/hold" - as it flushes keys / mouse buttons.

Ok. If you now removed the flushkeys/flushmouse commands when suspending/resuming your app, you could release "A" while suspended but for blitzmax it is "down/hold" when alt-tabbing in again - and it keeps "hold" until you tap "A" again.

@GWRon
Copy link
Contributor Author

GWRon commented Feb 13, 2018

One potential solution is to create some backup-arrays for the key and mouse states/hit-count.

When now suspending the app we iterate over all key/mouse states/hit-counts and backup them right before flushkey and flushmouse are called.

When now resuming the app, we iterate over all keys and mouse buttons (+ mouse location[2] as this is scroll wheel). During this iteration we need to refresh the current state of the key/button.

There are some possibilities:
it differs:
In that case we have to emit an event (as if it was coming from the OS) that a button/key is now down/up
hit-count needs to be kept reset as done by flushkeys and flushmouse.

it's the same:
Restore backup'd hit-count for the key/button (so "keyrepeat" and the likes work correct)

Problem I cannot solve for now: we need ways to check current key/button states of the OS.
For Windows we have GetKeyState:Short(key:int) we could use.
For Linux we could use https://tronche.com/gui/x/xlib/input/XQueryKeymap.html
or maybe we use something in the likes as:
https://www.unknowncheats.me/forum/c-and-c-/183880-linux-detecting-key-held-simulating-getasynckeystate.html

But for Mac I have no clue what would fit.

@woollybah
Copy link
Member

woollybah commented Feb 13, 2018 via email

@GWRon
Copy link
Contributor Author

GWRon commented Feb 13, 2018

Yes, the basic idea should be to "emulate" the missed information-events - at least if they are of "interest": means:

  • keys/buttons down in all cases
  • keys/buttons up on resume if down on suspend

In that case the events should get emitted so the default BlitzMax-implementation (SDL or "vanilla implementation") receives them as if the OS emitted key/button changes in a normal running/focused application.

"hitcount" is used somewhere, so the count should be restored - or the reset avoided. If the reset is avoided it must made sure to reset properly on a real "key up".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants