The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL virtual keypressed
sakulstra


Joined: 24 Jun 2014
Posts: 1
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 <cstdlib>
#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
SDL virtual keypressed
Jeffrey Carpenter
Guest

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


On 2014/06/ 25, at 6:15, sakulstra wrote:

Quote:
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(;Wink{
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org