0

In the PDF reader, we switch to the next page with the right arrow button. In my own winforms application, I assigned the right arrow key to the global hotkey and when I press the right arrow key it says "hello world" for trial purposes.

In this case, when I open the PDF reader and press the right arrow, it says "hello world" but it does not switch to the next pages. I want that when I press the right arrow button on the PDF reader, both switch to the next pages and say "hello world" because of the global hotkey assignment in my own winform application.

When I searched on Google, I couldn't find an article about such a situation. How can I achieve this?

3
  • If you put your code, in multiple applications, you have the same function on multiple applications. But you cannot modify other applications with C#/winforms. Commented Jan 18, 2020 at 18:41
  • 1
    You can use SendKeys.SendWait("{RIGHT}") to re-send the input (using RegisterHotKey, at least). You probably also need to add <add key="SendKeys" value="SendInput"/> in the <appSettings> section of app.config. Not all applications process this kind input, though. You may need to go deeper than that. Commented Jan 18, 2020 at 20:15
  • @Jimi - Thank you. I will try. I hope it opens a new door... Commented Jan 19, 2020 at 5:02

1 Answer 1

3

Based on Jimi's example:

public YourClass()
{
    InitializeComponent();
    //const int id = 0; // The id of the hotkey.
    // For eaxple hot key F5
    RegisterHotKey(Handle, 0, (int)KeyModifier.None, Keys.F5.GetHashCode());
}
protected override void WndProc(ref Message message)
{
    base.WndProc(ref message);
    if (message.Msg == 0x0312)
    {
        var id = message.WParam.ToInt32();
        if (id == 0)
        {
            /*
             * Write a method hee what you want to do.
            */
            // Let the command press the right arraybotton instead.
            SendKeys.SendWait("{RIGHT}");
        }
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

It's quite important to call UnregisterHotKey when the associated Handle is destroyed (i.e., the Form closes) or the current Thread (if hWnd is null) terminates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.