• Advertisement
Sign in to follow this  

SendInput to SDL apps

This topic is 4765 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently playing a game where, if you die, you go back to the beginning of the level. Because there's no saving option, I want to create a program that records my input into the game (or any other app) and is able to simulate that input at any time. Recording the input won't be a problem (I'm using windows XP by the way), but I've got problems with the simulation part. I've made a temporary program that uses SendInput (win32 API) to send a VK_UP message to a specific program. It works fine with, for example, the browser (opera), the file manager (explorer) and the text editor (notepad), but it doesn't seem to work with any SDL application. (and ofcourse my main target is an SDL game...) I don't know much about how SDL works internaly, but I know it should be possible with the win32 API because the on-screen keyboard that comes with windows XP (as an accessibility tool) DOES work with the SDL programs. The dependency walker tool that comes with VC++ studio tells me that the MS on-screen keyboard also uses the SendInput routine, but also a lot of other stuff, for example OpenInputDesktop. As far as I know SendInput is pretty low-level, but if any of you has a solution to this problem, I'd appreciate some help. (By the way, I already tried keybd_event). A piece of my code:
// wnd=TheGameWindow;

//
// Set focus
//
BringWindowToTop(wnd);
		
INPUT inp;
inp.type=INPUT_KEYBOARD;
inp.ki.wVk=VK_UP;
inp.ki.dwFlags=0;
inp.ki.time=0;
inp.ki.dwExtraInfo=0;

//
// Keydown
// (keybd_event(VK_UP, 0, 0, 0);)
//
if(SendInput(1, &inp, sizeof(INPUT)) != 1)
{
	MessageBox(NULL,"sendinput failed","error",MB_OK);
}


//
// Keyup
// (keybd_event(VK_UP, 0, KEYEVENTF_KEYUP, 0);)
//
inp.ki.dwFlags=KEYEVENTF_KEYUP;
if(SendInput(1, &inp, sizeof(INPUT)) != 1)
{
	MessageBox(NULL,"sendinput failed","error",MB_OK);
}


Share this post


Link to post
Share on other sites
Advertisement
UPDATE

I took a look at the SDL source in the online CVS repository, and I discovered that it has 3 windows sections:

//
// wincommon
//
The wincommon section doesn't contain any code involving normal keys (only checks system keystates).

//
// windib
//
http://www.libsdl.org/cgi/cvsweb.cgi/SDL12/src/video/windib/ (SDL_dibevents.c)

It uses the regular Peek- Get- DispatchMessage combination, dispatching it in the callback proc using the normal WM_KEYDOWN / WM_KEYUP checks, and sending it to the portable lib core. SDL doesn't check the system's keyboard state, but keeps track of an internal, portable, keyboard state.

It ignores all repeated keystrokes (managing repeatings internaly), but since de dwFlags member of the KEYBOARDINPUT structure that I'm sending is set to zero, this shouldn't be a problem.
There's also a TranslateKey routine that does make use of the GetKeyboardState routine to generate a unicode character from the message. However, a short examination of the SDL_PrivateKeyboard source shows that it still uses the virtual keycodes (VK_*) as primary identification, and that the unicodes are solely for compatibility purpose.

//
// windx5
//
http://www.libsdl.org/cgi/cvsweb.cgi/SDL12/src/video/windx5/ (SDL_dx5events.c)

It ignores WM_* keyboard messages, and uses DirectInput instead, which is bad isn't it? However the Dependency Walker saves the day: both the SDL.dll used by the game, and the game itself don't use any DirectX dlls. I guess this SDL version uses the windib backend.

Which leaves me right where I started...

(sorry about the long posts, just trying to inform you as well as possible).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement