C# 如何使用c注销特定热键#
我正在使用以下代码注册热键:C# 如何使用c注销特定热键#,c#,C#,我正在使用以下代码注册热键: RegisterGlobalHotKey(Keys.F4, USE_ALT); private void RegisterGlobalHotKey(Keys hotkey, int modifiers) { try { // increment the hot key value - we are just identifying //
RegisterGlobalHotKey(Keys.F4, USE_ALT);
private void RegisterGlobalHotKey(Keys hotkey, int modifiers)
{
try
{
// increment the hot key value - we are just identifying
// them with a sequential number since we have multiples
mHotKeyId++;
if (mHotKeyId > 0)
{
// register the hot key combination
if (RegisterHotKey(this.Handle, mHotKeyId, modifiers, Convert.ToInt16(hotkey)) == 0)
{
// tell the user which combination failed to register -
// this is useful to you, not an end user; the end user
// should never see this application run
MessageBox.Show("Error: " + mHotKeyId.ToString() + " - " +
Marshal.GetLastWin32Error().ToString(),
"Hot Key Registration");
}
}
}
catch
{
// clean up if hotkey registration failed -
// nothing works if it fails
UnregisterGlobalHotKey();
}
}
private void UnregisterGlobalHotKey()
{
// loop through each hotkey id and
// disable it
for (int i = 0; i < mHotKeyId; i++)
{
UnregisterHotKey(this.Handle, i);
}
}
RegisterGlobalHotKey(key.F4,使用\u ALT);
私有void注册表全局热键(键热键、int修饰符)
{
尝试
{
//增加热键值-我们只是识别
//因为我们有倍数,所以它们有一个序列号
mHotKeyId++;
如果(mHotKeyId>0)
{
//注册热键组合
if(RegisterHotKey(this.Handle,mHotKeyId,modifiers,Convert.ToInt16(热键))=0)
{
//告诉用户注册失败的组合-
//这对您有用,而不是最终用户;最终用户
//不应该看到此应用程序运行
MessageBox.Show(“错误:+mHotKeyId.ToString()+”-“+
Marshal.GetLastWin32Error().ToString(),
“热键注册”);
}
}
}
抓住
{
//如果热键注册失败,请进行清理-
//如果失败了,什么都不起作用
取消注册全局热键();
}
}
私有void UnregisterGlobalHotKey()
{
//循环检查每个热键id和
//禁用它
for(int i=0;i
如何注销热键并使Alt+F4继续工作?要仅注销Alt+F4,您需要使用注册热键时使用的相同id调用
UnregisterHotKey
方法
请参见此处的示例:您可以使用win32 api中的以下方法
[DllImport(“user32.dll”)]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
[DllImport(“user32.dll”)]
private static extern bool [UnregisterHotKey][1](IntPtr hWnd, int id);
是的,我尝试使用类似的函数作为RegisterHotKey,并将传递键hotkey和int修饰符作为参数。但我得到了一个构建错误:无法隐式地将int类型转换为bool如果我们不注销全局热键并关闭应用程序会发生什么?下一次跑步时有没有副作用?