6
我已經完成了使用以下代碼的兩個組合鍵的全局熱鍵。我怎樣才能做三個組合鍵(ctrl + shift + esc)(ctrl + shift + tab)的相同操作?如何註冊熱鍵使用c#的三個組合鍵#
代碼兩個組合鍵:
var TabShift = Keys.Tab | Keys.Shift;
RegisterGlobalHotKey(TabShift, USE_ALT);
DllImport("user32.dll")]
private static extern int RegisterHotKey(IntPtr hwnd, int id, int fsModifiers, int vk);
[DllImport("user32.dll")]
private static extern int UnregisterHotKey(IntPtr hwnd, int id);
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);
}
}
實際上,我不確定「Alt + Shift + Tab」是否可行,因爲它已經被任務切換器使用過,但是您明白了...... – 2010-06-04 01:48:45