C++ Question How to send a key to the core from a dll

yagni01

Addon Developer
Addon Developer
Donator
Joined
Feb 8, 2008
Messages
463
Reaction score
0
Points
16
Location
Atlanta, GA
I want to send keys to Orbiter to control items I can't find api methods for (e.g. I to toggle info, f to toggle FoV).

I've tried sendInput in a few variations but all that does is lock up the all keyboard input. Does anyone have an idea or working example?
 
Good question. I'd like to use that for similar access for a few new things myself.

Your method used to work, but quite a few versions ago. I did an RCS attitude controller that sent keystrokes before linear throttle commands were available in the API. It was a major PITA to use because it was slow and had to queue and multiplex out all the different axes required attitude thruster keystrokes.
 
I don't have a solution to generating key events, but you can set the FOV using oapiCameraSetAperture.
 
I don't have a solution to generating key events, but you can set the FOV using oapiCameraSetAperture.
Thanks, but its toggling the on-screen display of the info on and off that is the problem.
 
Yagni, I have tried: keybd_event, PostMessage with WM_COMMAND, SendMessage with WM_KEYUP and WM_KEYDOWN, and SendInput, but they have all failed to work.. So Orbiter might be using DirectInput for input rather then directly using the Win32 API.
 
I googled:
sendkeys to directinput

Looks like SendInput is supposed to work for DirectInput too. Perhaps there are examples or more info in those articles. Did you try your code on a simpler case like Notepad too, just to be sure that is working? It can get complicated.

I found some old code that is not hooked up anymore. (I last used it to send keys to PDF files to fill in my income taxes - how nerdy is that? ) It may not be the code that was used to drive Orbiter in olden times. It used keybd_event. I recall it being very tricky to use. e.g.: it has timers between key down and key up events, and so on.

By the way, are you testing on Vista? Some of the techniques I used to use weren't really supposed to work on XP, they just did. You weren't supposed to be able to talk to another process space or something, but it let you anyway. They might have "fixed" that anti-documented ability in Vista. (I thought DLLs were supposed to exist in the applications process space so perhaps this doesn't matter.)


-----Post Added-----


I adapted this C++ sendkeys system:
http://www.codeproject.com/KB/cpp/se...p_Article.aspx

I was able to send keystrokes (numpad keys) to Orbiter today in Vista like this:

CSendKeys sk;
sk.SendKeys(_T("{DELAY=1000}{appactivate Orbiter 2006}{DELAY=100}{NUMPAD2}{NUMPAD2}{NUMPAD2}{NUMPAD 6}{NUMPAD6}{NUMPAD6}"));

I tested it sending from an external program. Hopefully, it would work from within an Orbiter module also.

The problems I recall running into with string handling code from CodeProject, etc., were due to use of MFC-isms, or unicode. This one seems MFC free and simpler to integrate since the _T macro works transparently for unicode or not. Looking at it, I think it was almost a "drop in" to integrate it.

I have one note that indicates I needed to find a library function: atoi for _ttoi. atoi should be easy to find.

If you decide to try it out and hit a bump, you are welcome to my adaptation. Send me a PM.

My code has this note:
also see:
http://msdn2.microsoft.com/en-us/library/ms645540.aspx
for list of virtual keycodes
 
I asked Martin, and Orbiter does use Directinput for the keyboard input. However, it turns out that SendInput is able to send key commands to a DirectInput app, but you have to do a little trick.

http://www.elitepvpers.de/forum/war-hacks-bots-cheats-exploits/170258-simulating-keystrokes.html

http://www.gamedev.net/community/forums/topic.asp?topic_id=339282 (Last post)

I tested it and it works. I'm gonna post the link at OrbiterWiki "Interfacing to Orbiter" page.

EDIT: I just discovered you can use the OAPI_KEY_---- keys defined in OrbiterAPI.h inside the SendInput function and it works. Very convenient!
 
Last edited:
Brilliant! Looking forward to the wiki article (hint, hint)

Thanks to both of you!
 
Back
Top