简体   繁体   English

使用C#创建特殊的键盘快捷键

[英]create special keyboard shortcuts using C#

I want to create a special keyboard shortcut. 我想创建一个特殊的键盘快捷键。 I thought maybe to create a Windows forms app that the UI is empty, after turning on the pc, the program will open automatically, and will wait to the special shortcut. 我以为可能要创建一个UI空的Windows窗体应用程序,所以在打开PC后,程序将自动打开,并会等待特殊的快捷方式。 I thought maybe to create Event Handler for the shortcut(For example if 'E' and "M' are pressed), and than it will do what I will set up in the code. I'm facing a hardship in creating this EventHandler. Can you give me some tips or share your opinion? 我想也许可以为快捷方式创建事件处理程序(例如,如果按下“ E”和“ M”),那么它将完成我将在代码中进行的设置。我在创建此事件处理程序时遇到了困难。您能给我一些提示或分享您的意见吗?

Thanks 谢谢

You have a few options for running your Windows Form at startup. 在启动时,您有几种选择来运行Windows窗体。

1.You can use the Windows Task Scheduler to run the program at startup. 1.您可以使用Windows Task Scheduler在启动时运行程序。 In your bin/Release or bin/Debug, get the scheduler to run your YourFormName.exe program when Windows starts. 在bin / Release或bin / Debug中,获取计划程序以在Windows启动时运行YourFormName.exe程序。 How-To Geek has a pretty good tutorial on how to do this. How-To Geek有一个很好的教程。 2.You could also use the Windows Startup folder. 2.您也可以使用Windows启动文件夹。 Make a shortcut to the If you want it to run for just the current user, the path to the folder is 制作一个快捷方式,如果您希望它仅针对当前用户运行,则该文件夹的路径为

`C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup`

and for all users it is 对于所有用户来说

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Start-up

3.Then just drop a shortcut to your form (the same one I mentioned above) in one of these folders. 3.然后在这些文件夹之一中放一个快捷方式到您的表单(我上面提到的同一个)。 Another option is to register it in the Windows registry 另一个选择是在Windows注册表中注册它

using System.IO
namespace {
     {
public partial class TestForm:Form{
RegistryKey reg = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run","true");
public TestForm(){
reg.SetValue("MyApp",Application.ExecutablePath.ToString());
InitializeComponent();
                 }
            } 
      }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM