|
[a5] simulate keystroke? |
Mark Oates
Member #1,146
March 2001
|
Is it possible to simulate (trigger) a ALLEGRO_KEYBOARD_EVENT? or any event for that matter? I'm trying to make a software keyboard and would like to just fire the key normally like nothing fancy is going on. -- |
Dennis
Member #1,090
July 2003
|
I guess you could try using: No guarantees it would work but I don't see why it should not if you make sure to add 1024 to the event.type before emitting it. Then in the event evaluation, subtract 1024 from the type again if it's > 1024. e.g. if you want to emit an ALLEGRO_EVENT_KEY_DOWN, you fill an ALLEGRO_KEYBOARD_EVENT and set the type to (ALLEGRO_EVENT_KEY_DOWN + 1024) and then emit that. see also (snippet from the allegro source): /* Function: ALLEGRO_EVENT_TYPE_IS_USER * * 1 <= n < 512 - builtin events * 512 <= n < 1024 - reserved user events (for addons) * 1024 <= n - unreserved user events */ #define ALLEGRO_EVENT_TYPE_IS_USER(t) ((t) >= 512) It uses that in the emit user event function. Of course, you won't be able to fire the key to other applications that way, only your own code will be able to see/use it. --- 0xDB | @dennisbusch_de --- |
Audric
Member #907
January 2001
|
(edit: to Mark, about the general strategy) |
Thomas Fjellstrom
Member #476
June 2000
|
In the case of a soft keyboard, you should probably just send pseudo KEY_CHAR events rather than KEY_UP/KEY_DOWN. That is if all you care about is text input. -- |
weapon_S
Member #7,859
October 2006
|
Dennis said: al_init_user_event_source
Bad idea. |
Elias
Member #358
May 2000
|
I'd say a better method is to just use separate user events. Call them FAKE_UP / FAKE_DOWN and adjust your game's input handling to listen to those in addition to the regular keyboard events. Can also add a FAKE_CHAR or whatever the same way. Dennis' method should work of course, but it's a bit hackish. Alternatively, we could adapt the event handling to allow sending non-user events I guess. But for now you are supposed to create a user event source and send only user events from it. And someone should update the documentation of al_emit_user_event to explicitly forbid sending of non-user events. -- |
Thomas Fjellstrom
Member #476
June 2000
|
Elias said: Alternatively, we could adapt the event handling to allow sending non-user events I guess. But for now you are supposed to create a user event source and send only user events from it. And someone should update the documentation of al_emit_user_event to explicitly forbid sending of non-user events. Injecting input will probably be quite common, an al_inject/simulate_keypress might be something worth looking at. -- |
|