Incorrect key codes

Monkey Forums/Monkey Programming/Incorrect key codes

Samah(Posted 2011) [#1]
Strict

Import mojo

Function Main:Int()
       New TestApp
End

Class TestApp Extends App
       Method OnCreate:Int()
              SetUpdateRate(60)
              Return 0
       End
       
       Method OnUpdate:Int()
              If KeyHit(KEY_BACKSLASH) Then
                     Print "KEY_BACKSLASH"
              ElseIf KeyHit(220) Then
                     Print "220"
              End
              Return 0
       End
End


Testing in HTML5:
Press backslash, it prints "220".
KEY_BACKSLASH is defined as 226 in input.monkey.
There may be some other broken key codes too (check minus and plus).

Tested on Windows 7 32-bit and Windows XP SP2 32-bit, using "English (Australia) - US" input language.


marksibly(Posted 2011) [#2]
Hi,

Fixed backslash for V45.

KEY_MINUS works here, but there is no KEY_PLUS as that's a shifted '=' and the KEY consts are effectively 'raw' keys without modifiers - eg: there is no KEY_a const, only KEY_A.

Just noticed there are no keypad consts too. Will have a look at this but glfw seems to be problematic here...


Samah(Posted 2011) [#3]
@marksibly KEY_MINUS works here, but there is no KEY_PLUS as that's a shifted '='

I was talking about the numpad keys. For me (IIRC), pressing plus on the numpad gave me the same keycode as the equals key.
Regardless, my InputCache class in Diddy handles converting keycodes to characters, and takes shift into account.


Gerry Quinn(Posted 2011) [#4]
I'm getting a problem on HTML5 (Firefox). Every mouse button returns a left button hit. Right mouse button gives an annoying menu as well, but the left mouse button hit comes through straight away. Middle button is the same as left button.




marksibly(Posted 2011) [#5]
Hi,

This is beyond Monkey's control - as far as I know, HTML5 only supports the idea of 'a mouse button', and Monkey just treats this as a LMB.

The menu, middle button behavior are just how browsers choose to work.


skid(Posted 2011) [#6]
The standard I think supports event.button which should say which button:

http://www.w3schools.com/jsref/event_button.asp

Note that IE is of course non-standard...


Gerry Quinn(Posted 2011) [#7]
At least it looks like the left and right buttons can be detected unambiguously, whatever the browser. For most game interface purposes, those are the important ones.

I also notice the javascript applet in skid's link doesn't have the annoying Flash-like menu that appears when the right button is pressed in a Monkey app. Sure would be great to get rid of that, if it can be done!


marksibly(Posted 2011) [#8]
Hi,

It appears you can only trap RMB by installing the mousedown handler in HTML not JS, ie: this works:

<canvas id="GameCanvas" onmousedown="alert('Hi!')"...etc...>

...in MonkeyGame.html, but this...

canvas.onmousedown=function( e ){

...in main.js doesn't.

Anyone know how to get the JS version going? I'd prefer not to have a rats nest of dependencies between HTML/JS if possible...


skid(Posted 2011) [#9]
hmm, this works for me in IE and chrome:

<head>
<script>
function handler(){
	window.alert("alert:"+event.button)
};

function runme(){
	window.alert("hullo")	
	document.body.onmousedown=handler
}
</script>
</head>
<body onload=runme()>
hello
</body>



[edit]

and gives 0 2 and 1 2 for LMB/RMB for Chrome and IE respectively.

also, any chance we could have mousewheel support sometime in future?


marksibly(Posted 2011) [#10]
Hi,

So perhaps it's to do with *when* the handler's attached?

Can you try and mung a Monkey app to work? Had a quick shot but didn't get far.


marksibly(Posted 2011) [#11]
Hi,

Ok, adding this to the html5 canvas tag seems to do the trick on Chrome at least...

oncontextmenu="return false;"


marksibly(Posted 2011) [#12]
Hopefully all sweet in v45!


Gerry Quinn(Posted 2011) [#13]
RMB working fine on HTML now!

What has me scratching my head is the following question:

Flash has been a significant browser game platform for many years, and a dominant one for recent years. And you could never use the right mouse button. And I don;t recall any discussion about it. People just thought of it as one of those annoying things, I think.

Why weren't browser gae developers making a big fuss about this? It just seems very strange.

Of course now they will never fix it because tablets are becoming popular. But one-button devices were rare during many of the years when Flash was at its peak.


Foppy(Posted 2011) [#14]
You just don't really need the right mouse button in most games! :)


muddy_shoes(Posted 2011) [#15]
If you google "flash right click" you'll see that it has come up many times. It's just a sign of the dominance of Flash that it has become an expected limitation.


Foppy(Posted 2011) [#16]
I guess it's also because Apple computers have or had mice with only one button.


Samah(Posted 2011) [#17]
I guess it's also because Apple computers have or had mice with only one button.

I have a friend who's an Apple fanboy, and I love having a dig at him about this. :)