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?

Johnny Wind
  • 151
  • 8
  • 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. – Holger Jan 18 '20 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 `` in the `` section of `app.config`. Not all applications process this kind input, though. You may need to go deeper than that. – Jimi Jan 18 '20 at 20:15
  • @Jimi - Thank you. I will try. I hope it opens a new door... – Johnny Wind Jan 19 '20 at 05:02

1 Answers1

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}");
        }
    }
}
Habip Oğuz
  • 921
  • 5
  • 17
  • 3
    It's quite important to call [UnregisterHotKey](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-unregisterhotkey) when the associated Handle is destroyed (i.e., the Form closes) or the current Thread (if hWnd is null) terminates. – Jimi Jan 19 '20 at 09:30