• <tfoot id='bUx0K'></tfoot>
  • <small id='bUx0K'></small><noframes id='bUx0K'>

    1. <legend id='bUx0K'><style id='bUx0K'><dir id='bUx0K'><q id='bUx0K'></q></dir></style></legend>
      <i id='bUx0K'><tr id='bUx0K'><dt id='bUx0K'><q id='bUx0K'><span id='bUx0K'><b id='bUx0K'><form id='bUx0K'><ins id='bUx0K'></ins><ul id='bUx0K'></ul><sub id='bUx0K'></sub></form><legend id='bUx0K'></legend><bdo id='bUx0K'><pre id='bUx0K'><center id='bUx0K'></center></pre></bdo></b><th id='bUx0K'></th></span></q></dt></tr></i><div id='bUx0K'><tfoot id='bUx0K'></tfoot><dl id='bUx0K'><fieldset id='bUx0K'></fieldset></dl></div>

      • <bdo id='bUx0K'></bdo><ul id='bUx0K'></ul>

        如何使用 C# 禁用/覆盖 Windows 10 热键

        时间:2023-09-15
          <tbody id='9qMND'></tbody>

          <bdo id='9qMND'></bdo><ul id='9qMND'></ul>

          1. <tfoot id='9qMND'></tfoot>

              1. <i id='9qMND'><tr id='9qMND'><dt id='9qMND'><q id='9qMND'><span id='9qMND'><b id='9qMND'><form id='9qMND'><ins id='9qMND'></ins><ul id='9qMND'></ul><sub id='9qMND'></sub></form><legend id='9qMND'></legend><bdo id='9qMND'><pre id='9qMND'><center id='9qMND'></center></pre></bdo></b><th id='9qMND'></th></span></q></dt></tr></i><div id='9qMND'><tfoot id='9qMND'></tfoot><dl id='9qMND'><fieldset id='9qMND'></fieldset></dl></div>

                  <small id='9qMND'></small><noframes id='9qMND'>

                  <legend id='9qMND'><style id='9qMND'><dir id='9qMND'><q id='9qMND'></q></dir></style></legend>
                • 本文介绍了如何使用 C# 禁用/覆盖 Windows 10 热键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试注册某些热键,但我不能,因为它们是 Windows 默认设置.

                  I'm trying to register certain hotkeys, but I can't because they are Windows defaults.

                  CTRL+WIN+1 minimizes the current window. I'd like it to do something else.
                  I'd like to completely disable WIN+LEFT/RIGHT.
                  I'm also trying to handle the CTRL+WIN+Arrow in my own virtual desktop manager.
                  

                  zVirtualDesktop

                  如有必要,这必须使用 c# 和 Win32 API 来完成.它绝对不能使用 Autohotkey.

                  This has to be done using c# and Win32 API if necessary. It absolutely cannot use Autohotkey.

                  我发现的每一页都描述了如何使用 AutoHotKey 完成此操作.

                  Every page I find descibes how this can be done with AutoHotKey.

                  我会发布代码,但我真的不知道从哪里开始.我使用 Win32 注册热键.我认为有一种方法可以覆盖它们,但我找不到任何信息.

                  I'd post code, but I really don't know where to start. I use Win32 to register hotkeys. I assume there is a way to override them, but I can't find any info.

                  有人有想法吗?

                  推荐答案

                  可以使用键盘挂钩来做到这一点.一个很好的钩子类可以在这个 代码项目文章

                  It is possible to do this using a keyboard hook. A good hook class for this can be found on this CodeProject Article

                  使用以下代码将防止 WIN+LEFTWIN+RIGHT 发生.您可以使用它来覆盖您想要的任何键.

                  Using the below code will prevent the WIN+LEFT or WIN+RIGHT from occurring. You can use this to override whichever keys you'd like.

                  这甚至会覆盖您通过 RegisterHotKey Win API 添加的热键.

                  This will even override hotkeys which you added via RegisterHotKey Win API.

                  在项目中拥有这些类后,您可以将处理程序添加到静态 HookManager 类,如下所示.

                  Once you have those classes in your project you can add handlers to the static HookManager class like below.

                  //It's worth noting here that if you subscribe to the Key_Press event then it will break the international accent keys.
                  HookManager.KeyPress += HookManager_KeyPress;
                  HookManager.KeyDown += HookManager_KeyDown;
                  HookManager.KeyUp += HookManager_KeyUp;
                  

                  您也可以添加鼠标事件,但为简单起见,我只显示键盘挂钩.

                  You can also add mouse events, but for simplicity I'm just showing the keyboard hook.

                  我还创建了一个通用列表,以便知道哪些键当前处于关闭状态,并在 KeyUp 事件的列表中删除这些键.

                  I've also created a generic list so that I know which keys are currently down and I remove those keys from the list on the KeyUp event.

                  public static List<Keys> keysDown = new List<Keys>();
                  private static void HookManager_KeyDown(object sender, KeyEventArgs e)
                          {
                              //Used for overriding the Windows default hotkeys
                              if(keysDown.Contains(e.KeyCode) == false)
                              {
                                  keysDown.Add(e.KeyCode);
                              }
                  
                              if (e.KeyCode == Keys.Right && WIN())
                              {
                                  e.Handled = true;
                                  //Do what you want when this key combination is pressed
                              }
                              else if (e.KeyCode == Keys.Left && WIN())
                              {
                                  e.Handled = true;
                                  //Do what you want when this key combination is pressed
                              }
                  
                          }
                  
                          private static void HookManager_KeyUp(object sender, KeyEventArgs e)
                          {
                              //Used for overriding the Windows default hotkeys
                              while(keysDown.Contains(e.KeyCode))
                              {
                                  keysDown.Remove(e.KeyCode);
                              }
                          }
                  
                          private static void HookManager_KeyPress(object sender, KeyPressEventArgs e)
                          {
                              //Used for overriding the Windows default hotkeys
                  
                          }
                  
                          public static bool CTRL()
                          {
                              //return keysDown.Contains(Keys.LShiftKey)
                              if (keysDown.Contains(Keys.LControlKey) || 
                                  keysDown.Contains(Keys.RControlKey) || 
                                  keysDown.Contains(Keys.Control) || 
                                  keysDown.Contains(Keys.ControlKey))
                              {
                                  return true;
                              }
                              else
                              {
                                  return false;
                              }
                          }
                  
                          public static bool SHIFT()
                          {
                              //return keysDown.Contains(Keys.LShiftKey)
                              if (keysDown.Contains(Keys.LShiftKey) || 
                                  keysDown.Contains(Keys.RShiftKey) ||
                                  keysDown.Contains(Keys.Shift) ||
                                  keysDown.Contains(Keys.ShiftKey))
                              {
                                  return true;
                              }
                              else
                              {
                                  return false;
                              }
                          }
                  
                          public static bool WIN()
                          {
                              //return keysDown.Contains(Keys.LShiftKey)
                              if (keysDown.Contains(Keys.LWin) || 
                                  keysDown.Contains(Keys.RWin))
                              {
                                  return true;
                              }
                              else
                              {
                                  return false;
                              }
                          }
                  
                          public static bool ALT()
                      {
                          //return keysDown.Contains(Keys.LShiftKey)
                          if (keysDown.Contains(Keys.Alt) ||
                              keysDown.Contains(Keys.LMenu) ||
                              keysDown.Contains(Keys.RMenu))
                          {
                              return true;
                          }
                          else
                          {
                              return false;
                          }
                      }
                  

                  这篇关于如何使用 C# 禁用/覆盖 Windows 10 热键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 Windows 10 UWP 中复制和调整图像大小 下一篇:Windows 10 中桌面应用程序的 toast 通知中出现意外行为

                  相关文章

                  1. <small id='5i9zk'></small><noframes id='5i9zk'>

                  2. <tfoot id='5i9zk'></tfoot>

                        <bdo id='5i9zk'></bdo><ul id='5i9zk'></ul>
                      <legend id='5i9zk'><style id='5i9zk'><dir id='5i9zk'><q id='5i9zk'></q></dir></style></legend>
                    1. <i id='5i9zk'><tr id='5i9zk'><dt id='5i9zk'><q id='5i9zk'><span id='5i9zk'><b id='5i9zk'><form id='5i9zk'><ins id='5i9zk'></ins><ul id='5i9zk'></ul><sub id='5i9zk'></sub></form><legend id='5i9zk'></legend><bdo id='5i9zk'><pre id='5i9zk'><center id='5i9zk'></center></pre></bdo></b><th id='5i9zk'></th></span></q></dt></tr></i><div id='5i9zk'><tfoot id='5i9zk'></tfoot><dl id='5i9zk'><fieldset id='5i9zk'></fieldset></dl></div>