Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Kaio on Thu 05/12/2013 15:09:51

Title: Emulating a keyboard button
Post by: Kaio on Thu 05/12/2013 15:09:51
Hi guys!

I have a quick question and hope someone here can help me out. I'm trying to code a keyboard GUI for my game. The main platform should be Android, which is why I want to include the keyboard as a GUI.
Now, there's a function called ProcessClick. Is there something similar for the buttons of the keyboard? If the player clicks on the letter Q on my GUI, the game should emulate the button press on the keyboard.

Any suggestions?

Thank you very much
Kai
Title: Re: Emulating a keyboard button
Post by: Khris on Thu 05/12/2013 15:15:24
You can simply call on_key_press(eKeyQ), but that's kind of pointless, since you could just call the code triggered by (keycode == eKeyQ) instead.
Afaik there's no way to simulate a key press directly.

I suspect you're talking about entering text into textboxes, right? There's an icky workaround for this, but could you elaborate on the game situation first?
Title: Re: Emulating a keyboard button
Post by: Kaio on Thu 05/12/2013 15:21:39
Hey, thanks!

I want the keyboard GUI to pop up whenever the player has to type in something (e.g. a text box on another GUI, Save/Load etc.). Right now, I don't know how to perform a keyboard button press when clicking on a GUI button. I haven't found a way to do that...
Title: Re: Emulating a keyboard button
Post by: Khris on Thu 05/12/2013 17:46:46
Yeah, I thought this was about textboxes.
The only possibility I see is to iterate over all GUIs, and for those that are visible, over all their Controls. Every enabled textbox in those will have focus (and it should be only one).

You can now freely change that textbox's text, so you could simply append the character associated with the GUI button, or remove the last one upon clicking the backspace button.

You could even implement your own cursor (and use a label instead of a textbox if one can't hide the built-in one).

But you have to process everything manually.
Title: Re: Emulating a keyboard button
Post by: Kaio on Sun 08/12/2013 17:41:47
Okay, thank you for your help, Khris! I thought I'd have to do it this way, but simply hoped for a more elegant alternative (laugh)

cheers!