SDL virtual keypressed

Hello,
i’m looking for a multios solution to generate keyPressed events.( sth. like windows.h Sendinput() )
With the following code i can archive this goal with libsdl. My Problem is, that the keypressedEvent only gets handled by the sdlEvent queue.
Is there a way to send the pressed key to the focused window, even when it’s no sdl window(for example gedit/word/ofice or whatever)?

Code:

#ifdef __cplusplus
#include
#else
#include <stdlib.h>
#endif

#include “iostream”
#include “SDL.h”

int main(){
SDL_Init( SDL_INIT_EVERYTHING );
SDL_KeyboardEvent event;
event.which = 0;
event.keysym.sym = SDLK_x;
for(;;){
event.type = SDL_KEYDOWN;
event.state = SDL_PRESSED;
SDL_PushEvent((SDL_Event*)&event);
event.type = SDL_KEYUP;
event.state = SDL_RELEASED;
SDL_PushEvent((SDL_Event*)&event);

    SDL_Event pevent; /* Event structure */
    while(SDL_PollEvent(&pevent)) {  /* Loop until there are no events left on the queue */
      switch(pevent.type) { /* Process the appropriate event type */
        case SDL_KEYDOWN:  /* Handle a KEYDOWN event */
          std::cout << SDL_GetKeyName(pevent.key.keysym.sym) << std::endl;
          break;
        case SDL_KEYUP:  /* Handle a KEYDOWN event */
          printf("Oh! Key up\n");
          break;
        }
    }
}
return 0;

}

Regards,
thx in advance,
lukas

Hello,

As far as I understand it, the answer is no. The intended use of the API expects to be used within the context of a SDL window.

Cheers,
Jeffrey Carpenter
<@Jeffrey_Carpenter>On 2014/06/ 25, at 6:15, sakulstra wrote:

Hello,
i’m looking for a multios solution to generate keyPressed events.( sth. like windows.h Sendinput() )
With the following code i can archive this goal with libsdl. My Problem is, that the keypressedEvent only gets handled by the sdlEvent queue.
Is there a way to send the pressed key to the focused window, even when it’s no sdl window(for example gedit/word/ofice or whatever)?

Code:

#ifdef __cplusplus
#include
#else
#include
#endif

#include “iostream”
#include “SDL.h”

int main(){
SDL_Init( SDL_INIT_EVERYTHING );
SDL_KeyboardEvent event;
event.which = 0;
event.keysym.sym = SDLK_x;
for(;;){
event.type = SDL_KEYDOWN;
event.state = SDL_PRESSED;
SDL_PushEvent((SDL_Event*)&event);
event.type = SDL_KEYUP;
event.state = SDL_RELEASED;
SDL_PushEvent((SDL_Event*)&event);

    SDL_Event pevent; /* Event structure */
    while(SDL_PollEvent(&pevent)) {  /* Loop until there are no events left on the queue */
      switch(pevent.type) { /* Process the appropriate event type */
        case SDL_KEYDOWN:  /* Handle a KEYDOWN event */
          std::cout << SDL_GetKeyName(pevent.key.keysym.sym) << std::endl;
          break;
        case SDL_KEYUP:  /* Handle a KEYDOWN event */
          printf("Oh! Key up\n");
          break;
        }
    }
}
return 0;

}

Regards,
thx in advance,
lukas


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org