Problem virtual keyboard events

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
11,324
Reaction score
2,805
Points
203
Location
between the planets
I'm currently programming the system switch for orbiter galaxy, which basically just means that Orbiter gets closed by a virtual keyboard input (i.e. the program "simulates" that ctrl+Q has been pressed) and started up again.

For this I copied over the code from MsssMFD, which looks like this (only the ctrl+Q thingy):

Code:
    keybd_event(VK_CONTROL, 0, 0, 0);
    keybd_event(81, 0, 0, 0);
    keybd_event(81, 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
The code gets properly executed, but nothing happens. Is this method no longer possible with Orbiter 2010, or is there something wrong in that code (allthough it works quite flawlessly in MsssMFD in Orbiter 2006)? or is there an API-call for shutting Orbiter down?
 
Ctrl-Q is no longer queried from the windows message loop, but directly via the DirectInput interface. If keybd_event sends a WM_CHAR message, this no longer has an effect. You have to use a lower level method. I remember that there was a Windows function that does it in such a way that DirectInput picks it up, but I don't remember what it was. A forum search may help.
 
You can also close Orbiter by sending the Orbiter window a WM_CLOSE message. Like so:

SendMessage(orbiter, WM_CLOSE, 0, 0); - Where "orbiter" is the Window handle.
You can cache the Window handle in the opcOpenRenderViewport callback function.

edit:

This works fine in the last two shut-down methods, "Respawn Orbiter Process" and "Terminate Orbiter Process". However in the first shutdown method Orbiter crashes after the launchpad is displayed.
 
Last edited:
You can also close Orbiter by sending the Orbiter window a WM_CLOSE message. Like so:

SendMessage(orbiter, WM_CLOSE, 0, 0); - Where "orbiter" is the Window handle.
You can cache the Window handle in the opcOpenRenderViewport callback function.

edit:

This works fine in the last two shut-down methods, "Respawn Orbiter Process" and "Terminate Orbiter Process". However in the first shutdown method Orbiter crashes after the launchpad is displayed.
Does it work if you use "PostMessage" instead of "SendMessage"?
 
An explanation of the exact difference of the three would be handy. As I've heard, OGLA will only work with the later two options anyways.

I'll try out the suggested method, since it seems a much handier way than emulating a key-input.

---------- Post added at 02:53 PM ---------- Previous post was at 01:54 PM ----------

Tried and works. PostMessage works with all three shutdown methods, thanks Martin!
 
Back
Top