Simulate keypress inside a gui button

Started by Knox, Mon 07/06/2010 20:52:09

Previous topic - Next topic

Knox

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):
Code: ags

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.
--All that is necessary for evil to triumph is for good men to do nothing.

Calin Leafshade

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.

Knox

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...
--All that is necessary for evil to triumph is for good men to do nothing.

Ryan Timothy B

I imagine you could check the newly added character and remove it once it's added if it's not an acceptable character.

Knox

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
--All that is necessary for evil to triumph is for good men to do nothing.

SMF spam blocked by CleanTalk