Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Knox on Mon 07/06/2010 20:52:09

Title: Simulate keypress inside a gui button
Post by: Knox on Mon 07/06/2010 20:52:09
Hi,

Probably another simple 1 question/1 answer deal, but Ive been searching for a solution to this for a while without luck.

Im aware you can simulate mouse clicks within GUI buttons, but what about simulating actual keyboard buttons within GUI buttons? What Im trying to do is I have a button that Id like to simulate the "Backspace" key so that when the player clicks on that button, it will act as if the actual Backspace key was pressed and deletes characters in a text box. I know I can just press the actual "Backspace" key, but Id rather it be called not by pressing the actual keyboard in real life but by clicking the "fake" keyboard button within the GUI I created.

Something like this (which doesnt work, of course):

function btnRadio_Delete_OnClick(GUIControl *control, MouseButton button)
{
  on_key_press(eKeyBackspace);
}


I tried to get around that with the truncate command with the string in the text box, and I guess I can get that to work with a hack but I thought it would be easier to just somehow tell AGS that when that particular button is pressed, pretend it acts like the actual keyboard "backspace" key.
Title: Re: Simulate keypress inside a gui button
Post by: Calin Leafshade on Mon 07/06/2010 21:39:30
The problem with that is that as soon as you click the button, the text box looses focus and so the text box never registers the keypress.

Edit: also the engine will handle the keypresses *before* the on_keypress function so it wouldnt help anyway.. your truncate method is perfectly fine.
Title: Re: Simulate keypress inside a gui button
Post by: Knox on Mon 07/06/2010 22:14:29
Ah ok...well atleast the trunc works.

So Im guessing its probably impossible too to disable just "some" keypresses when a textbox is enabled and visible, while enabling just the others? Right now I think its a "disable" or "enable" kinda deal, no exceptions, huh...
Title: Re: Simulate keypress inside a gui button
Post by: Ryan Timothy B on Mon 07/06/2010 22:19:51
I imagine you could check the newly added character and remove it once it's added if it's not an acceptable character.
Title: Re: Simulate keypress inside a gui button **SOLVED**
Post by: Knox on Fri 11/06/2010 16:45:20
Well I actually created a listbox with all the possible options so when you select an item in that box, it updates the textbox in my radio screen...so for now I decided to disable the textbox for user-input :P