[英]Shortcut in Visual Studio - Windows Form Application while other Window is active
我想在Windows Form App中使用快捷方式,并找到以下代码 。
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
if (keyData == (Keys.Enter)) {
MessageBox.Show("Hello World!");
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
但这仅在窗口处于活动状态时有效。 即使其他窗口处于活动状态,如何使用快捷方式?
您可以使用单个入口点以基本形式来捕获和分发消息。
基本形式
public class BaseForm : Form
{
public void MyMessage(hwnd:HWND)
{
...
case MSG_SPECIFIC_ACTION_1 : handled=this.DoOnSpecificAction1();
...
}
protected bool DoOnSpecificAction1(){ return=false;}
}
基本形式后代
public class MyCustomForm : BaseForm
{
protected override bool DoOnSpecificAction1()
{
MessageBox.Show("Hello");
return true;
}
}
编辑-全局KeyboardHook
如果要在其他应用程序中捕获所有键事件,则需要使用键盘钩。 这是一篇不错的文章,描述了如何使用SetWindowsHookEx
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.