c# winforms - 是否可以在多个应用程序上使用全局热键 [英] c# winforms - is it possible to use global hotkey on multiple applications

查看:19
本文介绍了c# winforms - 是否可以在多个应用程序上使用全局热键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 PDF 阅读器中,我们使用右箭头按钮切换到下一页.在我自己的 winforms 应用程序中,我将右箭头键分配给全局热键,当我按下右箭头键时,它会显示hello world"以供试用.

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.

在这种情况下,当我打开 PDF 阅读器并按向右箭头时,它会显示hello world",但不会切换到下一页.我希望当我按下 PDF 阅读器上的右箭头按钮时,由于我自己的 winform 应用程序中的全局热键分配,两者都切换到下一页并说hello world".

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?

推荐答案

基于吉米的例子:

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}");
        }
    }
}

这篇关于c# winforms - 是否可以在多个应用程序上使用全局热键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆