[英]Setting application-wide hotkey in C#
您可以為應用程序創建基本表單,並將keypreview屬性設置為true並處理keydown事件,以便所有表單都具有相同的鍵定義。
您還可以使用以下例程為表單注冊熱鍵,但是在此方法中,您將需要在每個表單的load事件上調用相同的方法。
protected override bool ProcessCmdKey(ref Message message, Keys keys)
{
switch (keys)
{
case Keys.F2 | Keys.Control:
//Process action here.
return false;
}
return false;
}
您還可以從user32.dll使用以下非托管方法,但我當然不建議這樣做。
static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint virtualKey);
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.