簡體   English   中英

熱鍵以外的其他C#組合鍵

[英]key combination c# other than hotkeys

我正在實現快捷鍵組合邏輯,例如

Ctrl + A

Ctrl + Alt + D

但是現在我正在尋找一種技巧來實現沒有熱鍵組合的鍵盤鍵組合: A + D但沒有得到任何正確的東西。

因此,請幫助實施它。

更新

目前我無法添加除熱鍵組合以外的其他組合鍵,因為每當我按下兩個鍵時,例如: **A + D**它僅返回單鍵ascii,因此我無法獲得兩個鍵組合。

我使用了以下內容http://www.codeproject.com/Articles/442285/Global-Shortcuts-in-WinForms-and-WPF

過去,我使用GetKeyState Api(在類似的類中用於捕獲系統范圍的快捷方式)。 也許現在有新的變體可用(我相信WPF有一個KeyBoard.IsKeyDown),但這應該仍然有效:

    [DllImport("user32", CharSet = CharSet.Auto,
    ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
    static extern short GetKeyState(int keyCode);

    public static bool CheckKeysPressed(params Keys[] keys)
    {
        for (int i = 0; i < keys.Length; i++)
            if (!CheckKeyPressed((int)keys[i])) return false;
        return true;
    }
    public static bool CheckKeyPressed(Keys key)
    {
        return CheckKeyPressed((int)key);
    }
    public static bool CheckKeyPressed(int vkey)
    {
        short ks = GetKeyState(vkey);
        return ks == 1;
    }

用法: if(CheckKeysPressed(Keys.A, Keys.D)) {/*...*/}

聲明2個bool變量(例如IsADownIsDDown ),並在AD的事件上都它們聲明為“ true ”。 這兩項活動同時檢測是否有其他bool關閉或無法。 如果是這樣,則在按下兩個按鈕的同時進行操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM