KeyHit acting like KeyDown

Monkey Forums/Monkey Bug Reports/KeyHit acting like KeyDown

Goodlookinguy(Posted 2013) [#1]
Version: 68/69
Affecting: HTML5, GLFW, Flash (not XNA)

After a few updates KeyHit starts registering a key being held down as KeyHit.

There's a different thread discussing it a bit here, because I thought that I might just have had the wrong Flex version: http://www.monkeycoder.co.nz/Community/posts.php?topic=4827

This is the test, I also built it for both v66 and v69 so that you could see the difference quickly.


Import mojo

Function Main:Int()
	New Example()
	Return 0
End

Class Example Extends App
	Method OnCreate()
		SetUpdateRate(30)
	End
	
	Field x:Int, y:Int
	
	Method OnUpdate()
		If KeyHit(KEY_SPACE)
			x = MouseX()
			y = MouseY()
		End
	End
	
	Method OnRender()
		Cls()
		
		SetColor(255, 255, 255)
		DrawCircle(x, y, 5)
	End
End



marksibly(Posted 2013) [#2]
Nice find! Key repeat is not being ignored...

Fixed in next update, and now also available here:

https://github.com/blitz-research/monkey/blob/master/modules/mojo/inputdevice.monkey


ziggy(Posted 2013) [#3]
I liked this for my GUI edit controls. it behaved like a regular GUI. Any chance to make this work when required? or having a KeyRepeat function or the like?


marksibly(Posted 2013) [#4]
GetChar should be used for detecting key repeats, and 'GUI' type key events in general.

It returns a unicode char, so there are some extra CHAR_ 'pseudo-unicode' consts in input.monkey for detecting repeating non-char keys like delete, up etc. That said, I haven't tested these out since the change to v67...will do so soon.

KeyDown/KeyHit are intended more for reporting 'raw' key events - ie: what the user is actually doing.


Midimaster(Posted 2013) [#5]
by the way....
do you see a possibility of catching those additional characters of a android virtual keyboard, that appear, if you press a key longer? This would be very helpful for german umlauts "ä" "ö" and "ü"?


ziggy(Posted 2013) [#6]
Is there a way to do a non-flushing GetChar?


marksibly(Posted 2013) [#7]
> Is there a way to do a non-flushing GetChar?

Something like PeekChar? No there's not, although it'd be pretty easy to add - why do you need it?

Chars are actually queued so you don't miss any and should be read in a loop, eg:

Repeat
  Local c:=GetChar()
  If Not c Exit
  DispatchChar c   'send char to 'focus' window or whatever
Forever



ziggy(Posted 2013) [#8]
I need it becouse in JungleGui, the Gui system is "listening" to any keypress to launch events, and it is great that it does not "stole" keypress data. I mean, if the Application being developed with the Gui system includes a Monkey game that also needs GetChar, this information will be lost for the games as it will be consumed by the Gui system. The junglegui system is designed to create editor for games, so it is a good idea to make it easy to add/remove to games without having to change the game code (as in this example: http://www.jungleide.com/samples/junglegui05/MonkeyGame.html ). I can think on workaraounds, but if it is possible/easy to add, it can be more elegant.