generating fake keyboard events? (gui buttons etc)
-
- Posts: 1010
- Joined: Mon Oct 24, 2011 10:03 pm
- Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d
generating fake keyboard events? (gui buttons etc)
This would allow me to implement the requisite movement gui buttons as well, if not I'll have to put in more work on them but fake key events would be the best because I already have the timing logic for keyboard inputs.
"this is not the bottleneck you are looking for"
Re: generating fake keyboard events? (gui buttons etc)
IrrlichtDevice has a postEventFromUser function which can be used for that. Thought I doubt it's a good idea to fake the input for this specific case. Probably better to move your timing logic to some input or movement controller class and call that from the input receiver and from whereever you need it now. Reason is that it's likely not about keys but about input (or movement) and your interfaces (and classes) should generally reflect what's really going on. But not knowing what you are doing maybe I'm wrong :-) (for example I do use postEventFromUser myself when writing automatic tests so scripts can fake clicking gui-elements).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 1010
- Joined: Mon Oct 24, 2011 10:03 pm
- Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d
Re: generating fake keyboard events? (gui buttons etc)
oh the reason I want to do it is so I can have one simple interface, it checks if a specific keyboard event has been triggered and performs said action (if the 200ms timer is up)
otherwise I'd need to duplicate my code for gui events, it should behave the same as a keyboard event so I'll try it.
EDIT: welp it's harder to use than I thought.
\mainGame.cpp|174|error: invalid use of 'struct irr::SEvent::SKeyInput'|
of course it has to be vague I also tried creating a KeyInput
but that gives
\mainGame.cpp|174|error: no match for call to '(irr::SEvent::SKeyInput) (wchar_t, bool, irr::EKEY_CODE, bool, bool)'|
I'm clearly doing SOMETHING wrong.
otherwise I'd need to duplicate my code for gui events, it should behave the same as a keyboard event so I'll try it.
EDIT: welp it's harder to use than I thought.
Code: Select all
SEvent event;
event.SKeyInput(L'w', false, irr::KEY_KEY_W, true, false);
of course it has to be vague I also tried creating a KeyInput
but that gives
\mainGame.cpp|174|error: no match for call to '(irr::SEvent::SKeyInput) (wchar_t, bool, irr::EKEY_CODE, bool, bool)'|
so... apparently (wchar_t, bool, irr::EKEY_CODE, bool, bool) != (wchar_t, bool, irr::EKEY_CODE, bool, bool)... odd.irr::SEvent::SKeyInput Struct Reference
Any kind of keyboard event. More...
#include <IEventReceiver.h>
List of all members.
Public Attributes
wchar_t Char
Character corresponding to the key (0, if not a character)
bool Control:1
True if ctrl was also pressed.
EKEY_CODE Key
Key which has been pressed or released.
bool PressedDown:1
If not true, then the key was left up.
bool Shift:1
True if shift was also pressed.
I'm clearly doing SOMETHING wrong.
"this is not the bottleneck you are looking for"
Re: generating fake keyboard events? (gui buttons etc)
Here's some code where I use it in my game, do it somehow like that:
edit: you don't need the StringToIrrKey function if you know exactly which keys you send - that's just to make it more general. If you need that as well you can find it in src/keycode_strings.cpp/.h in my racer sources: https://bitbucket.org/mzeilfelder/trunk_hc1
(the other code is also from there from the app_tester.cpp)
Code: Select all
void AppTester::SendLMouseEvent(const irr::core::position2di& pos, bool down)
{
irr::SEvent event;
event.EventType = irr::EET_MOUSE_INPUT_EVENT;
event.MouseInput.Event = down ? irr::EMIE_LMOUSE_PRESSED_DOWN : irr::EMIE_LMOUSE_LEFT_UP;
event.MouseInput.Control = 0;
event.MouseInput.Shift = 0;
event.MouseInput.X = pos.X;
event.MouseInput.Y = pos.Y;
irrlichtDevice->postEventFromUser(event);
}
void AppTester::SendKeyEvent(const char * key, bool down)
{
if ( key )
{
irr::SEvent event;
event.EventType = irr::EET_KEY_INPUT_EVENT;
event.KeyInput.Char = 0; // probably setting it to wchar_t(key) makes more sense for you
event.KeyInput.Key = StringToIrrKey( std::string(key) );
event.KeyInput.PressedDown = down;
event.KeyInput.Shift = false;
event.KeyInput.Control = false;
irrlichtDevice->postEventFromUser(event);
}
}
(the other code is also from there from the app_tester.cpp)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 1010
- Joined: Mon Oct 24, 2011 10:03 pm
- Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d
Re: generating fake keyboard events? (gui buttons etc)
oh, thanks
I told you I was doing something wrong.
I told you I was doing something wrong.
I'll keep that in mind if I need a generalized solution in the future, but for now I only need a handful of specific events.edit: you don't need the StringToIrrKey function if you know exactly which keys you send
"this is not the bottleneck you are looking for"