Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hello,

does anyone know how i can perform a long press of a key in FSUIPC using C# ?

Right now i perform a "normal" keypress using
FSUIPCConnection.SendKeyToFS(Keys k, SendModifierKeys mod);
But tihs simulates just a "Keypress" and not a longer press of a Key.

Matthias

Posted

I'll can a new method for this. Probably SendKeyHoldToFS. You'll be able to specify how long to hold the key for. 

Would that be suitable or do you need separate key down/up calls and do the timing yourself?

Paul

Posted

Hello,
that would be nice.
But i think there must be any method,  or maybe a time in seconds in the method for the release of the Key.
Otherwiese it keeps being pressed 🙂
If you create this Method, please dont forget the Modifier Keys like shift,alt, strg 😉
Matthias

Posted

I've tried this here using the Key_Press_and_Hold control. It may not do what you're expecting.

It doesn't repeat the key until you call the release command. So you don't get the action repeating.

You can try it for yourself and see if it does what you're expecting... Just paste this into your code and call.

sendKeyHoldToFS - holds the key for the specified HoldTime (in milliseconds) then releases it.

sendKeyDownToFS - presses the key down but does not release it.

snedKeyUpToFS - releases the key.

        private void sendKeyHoldToFS(Keys Key, SendModifierKeys Modifiers, int HoldTime)
        {
            // First make sure FSX has the focus
            SendControlToFS(FSUIPCControl.Key_focus_restore, 0);
            // Wait for focus change
            Thread.Sleep(150); 
            // Send the key down
            SendControlToFS(FSUIPCControl.Key_Press_and_Hold, (int)Key + ((int)Modifiers * 256));
            // Wait
            Thread.Sleep(HoldTime);
            // send the key up
            SendControlToFS(FSUIPCControl.Key_Release, (int)Key + ((int)Modifiers * 256));
        }

        private void sendKeyDownToFS(Keys Key, SendModifierKeys Modifiers, int HoldTime)
        {
            // First make sure FSX has the focus
            SendControlToFS(FSUIPCControl.Key_focus_restore, 0);
            // Wait for focus change
            Thread.Sleep(150);
            // Send the key down
            SendControlToFS(FSUIPCControl.Key_Press_and_Hold, (int)Key + ((int)Modifiers * 256));
        }

        private void sendKeyUpToFS(Keys Key, SendModifierKeys Modifiers, int HoldTime)
        {
            // First make sure FSX has the focus
            SendControlToFS(FSUIPCControl.Key_focus_restore, 0);
            // Wait for focus change
            Thread.Sleep(150);
            // Send the key down
            SendControlToFS(FSUIPCControl.Key_Release, (int)Key + ((int)Modifiers * 256));
        }

Paul

  • Like 1

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.