Game Development Community

Using anyKey to pass keystrokes

by Rich Adam · in Torque 3D Professional · 02/05/2010 (4:22 am) · 5 replies

I have a mode in which I wish to pass all keyboard input to another process. I can define and activate a new action map and use:

myMap.bindCmd(keyboard, "anyKey", "", "sendKey();");

How do I get access to which key was pressed so I can pass it on in sendKey?

photonically yours,
rda

#1
02/05/2010 (11:06 am)

You can't. ActionMap isn't passing along any information about this.

I think you have three options:


  1. Populate an ActionMap where each key is bound to a different function that then passes its information on to sendKey.
  2. Modify the source code.
  3. Put a GuiInputCtrl on your PlayGui and let it sink all keyboard events. It will let the mouse events pass through to the action map but will pass on keyboard events using the "onInputEvent" callback complete with all information you need.

Almost needless to say that 3. is by far the most elegant.
#2
02/08/2010 (10:35 pm)
So I have been able to take the keys and pass them into my process with some interpretation for "space" "return" etc. to virtual key codes. But I cannot seem to get the mouse events to be passed through to the action map.

I had to create a separate profile ( from GuiDefaultProfile) that set modal to true in order to get any inputs into onInputEvent. But now the action map is not getting any event as far as I can tell. From my reading the modal field enables the pass through of events. Any ideas about what might not be set up properly?

Thanks.
#3
02/10/2010 (8:07 am)

Sorry, didn't have the time to look much further into this yet, but you're right--it's not letting mouse events pass through which is kind of nonsense as it is not doing anything else with them.

I'll give this a more thorough look soon. IMO, GuiInputCtrl could use a refactor to become more useful.

BTW, the key property in the GuiControlProfile for it to work is canKeyFocus since otherwise the ctrl cannot become first responder. modal can be set either way.
#4
02/10/2010 (5:52 pm)
I ended up using option 2 which was the most elegant of my remaining choices. It is working now, thanks for your help. I might have wasted a bunch of time trying to get our alternate action map approach to work.
#5
02/10/2010 (5:59 pm)

Sorry to have led you in a dead-end with GuiInputCtrl. I'll definitely make sure, though, to look into this more during the beta phase and make sure 3 is a viable option in the future.