Jump to content
The simFlight Network Forums

SendKeyToFS not working, SendControlToFS does


nadimaj

Recommended Posts

Hi all,

Prepar3D 4.5.13

FSUIPC 5.1.5.7

C# .NET (Framework vs 4.7)

First time I'm dabbing with this. Using the latest Nuget reference (v3.1.24.339). I'm successfully able to manipulate the sim using SendControlToFS but SendKeyToFS does nothing. The sample application is able to send keys fine though (I can pause using the button)

//FSUIPCConnection.SendControlToFS(FsControl.PAUSE_TOGGLE,0); //Works
FSUIPCConnection.SendKeyToFS(Keys.P); //Doesn't work

Thanks!

 

Link to comment
Share on other sites

1 hour ago, Paul Henty said:

Hi,

I'm not sure what the problem could be if the sample app works. 

When you use this function is P3D obtaining the focus okay? Does it the P3D window come to the foreground and un-grey it's title bar?

Paul

Hi guys,

I have had this issue as well. I am not certain because I have not tested much, but I believe this is a problem when P3D is full screen. Also, it seems when doing multiple keypress combinations there has to be a built in delay between keypresses or P3D will not see them after the first key. In windowed mode in order to get the P3D menu to respond to FSUIPC keypresses I have to insert at least a two second delay. E.G. "ALT", delay 2 seconds, "S". I sure wish there was another way to control the menus...

James

Link to comment
Share on other sites

Problem is there regardless of Fullscreen for me. Interestingly, P3D seems unresponsive to any externally originating key sends. I've managed to write something using the SendKeys method available within .NET and that too cannot send keys to P3D, but works fine with Notepad. A bit of research on the web suggests this is related to Microsoft's UAC which thinks it's being clever by blocking external key events. I've tried launching everything as Administrator and disabling UAC, still doesn't work though.

Paul, is there any thing about your sample app which might be getting around UAC or something similar? The focus behaviour is exactly as you describe.

Link to comment
Share on other sites

Quote

Slight eureka moment. Works outside of my Timer but not when called from within the Timer.Tick event. 

Okay, I'm posting a modified version of SendKeyToFS below for you to try. Can you copy this into your code somewhere and use that instead (in your timer event).

If it still doesn't work, please experiment with the timeout between when it gives focus to P3D and sending the keystroke. It might work with a larger delay. 150ms was fine for FSX but maybe P3D needs longer to be ready. Maybe 250 or even 500?

        private void SendKeyToFS(Keys Key, SendModifierKeys Modifiers)
        {
            // First make sure the Flight Sim has the focus
            SendControlToFS(FSUIPCControl.Key_focus_restore, 0);

            // Please experiment with this delay if this doesn't work            
            Thread.Sleep(150); 

            // Send the key 
            SendControlToFS(FSUIPCControl.Key_Press_and_Release, (int)Key + ((int)Modifiers * 256));
        }

 

Paul

 

Link to comment
Share on other sites

Perfect. Works a treat. Thank you very much Paul. FYI though, works just fine even without the Thread.Sleep (tried 0 then completely removed the line). As I said above, seems to be a generic problem with any externally (app) generated key events not being sent to P3D. Though the above is a great workaround for FSUIPC.

Link to comment
Share on other sites

14 hours ago, nadimaj said:

Perfect. Works a treat. Thank you very much Paul. FYI though, works just fine even without the Thread.Sleep (tried 0 then completely removed the line). As I said above, seems to be a generic problem with any externally (app) generated key events not being sent to P3D. Though the above is a great workaround for FSUIPC.

Curious, does this work on the menu bar??

James

Link to comment
Share on other sites

  • 1 year later...
On 12/29/2020 at 10:47 AM, Paul Henty said:

Great, thanks for that. I'm currently working on a new version of the DLL. I'll include this fix in the next release in a week or so.

Paul

Hello Paul,

Could you please help me how to call Ctrl + Shift with Send KeyToFS ? 

What im using here is only with Ctrl.

FSUIPCConnection.SendKeyToFS(Keys.F1, SendModifierKeys.Control, null);

I want to send Ctrl + Shift + F1.

Thank you

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.