第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何調(diào)整 Cheet.NET 以綁定到我的 C# 表單?

如何調(diào)整 Cheet.NET 以綁定到我的 C# 表單?

C#
海綿寶寶撒 2023-08-20 09:49:39
所以我在設(shè)置一個(gè)按鍵綁定來(lái)在我的項(xiàng)目中執(zhí)行某些操作時(shí)遇到問(wèn)題(右 Alt + 左 Control)我嘗試使用一個(gè)名為 Cheet.NET 的 API,它表示它可以輕松地調(diào)整項(xiàng)目并允許制作可以調(diào)用函數(shù)的自定義“konami”代碼。因此,我使用 Visual Studio 中的 NuGet 包管理器安裝了它,保存并重新加載了我的項(xiàng)目?;貋?lái)后,嘗試編寫一個(gè)簡(jiǎn)單的按鍵綁定,我已經(jīng)從初始化代碼中得到了很多錯(cuò)誤:// Initializationvar cheet = new Cheet();myUIElement.PreviewKeyDown += cheet.OnKeyDown;cheet.Map("↑ ↑ ↓ ↓", () => { Debug.WriteLine("Voilà!"); } );這是我放置代碼的地方:namespace WindowsFormsApp1{? ? public partial class Form1 : Form? ? {? ? ? ? // Initialization? ? ? ? var cheet = new Cheet();? ? ? ? myUIElement.PreviewKeyDown += cheet.OnKeyDown;? ? ? ? cheet.Map("↑ ↑ ↓ ↓", () => { Debug.WriteLine("Voilà!"); });? ? ? ? public Form1()? ? ? ? {? ? ? ? ? ? InitializeComponent();? ? ? ? }? ? ? ? private void Form1_Load(object sender, EventArgs e)? ? ? ? {? ? ? ? }? ? }}它無(wú)法識(shí)別很多代碼,并且也給了我很多計(jì)算錯(cuò)誤:類、結(jié)構(gòu)或接口成員聲明中的標(biāo)記“+=”無(wú)效預(yù)期元組必須包含至少兩個(gè)元素 類、結(jié)構(gòu)或接口成員聲明中的標(biāo)記“+=”無(wú)效我聽(tīng)說(shuō)我應(yīng)該將包“綁定”到我的項(xiàng)目,但我不知道該怎么做。感謝任何未來(lái)的幫助。
查看完整描述

3 回答

?
紅顏莎娜

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超13個(gè)贊

最簡(jiǎn)單的是,您幾乎可以從 github 復(fù)制/粘貼 Wpf 實(shí)現(xiàn),并更改為使用適用于 Windows 表單的正確事件處理程序/枚舉:


using CheetNET.Core;

using System;

using System.Text.RegularExpressions;

using System.Windows.Forms;


public class Cheet : Cheet<System.Windows.Forms.Keys>

{

    private static readonly Regex LetterKeysNamePattern = new Regex(@"^[a-z]$");

    private static readonly Regex NumberKeysNamePattern = new Regex(@"^[0-9]$");

    private static readonly Regex KeyspadNumberKeysNamePattern = new Regex(@"^kp_[0-9]$");

    private static readonly Regex FunctionKeysNamePattern = new Regex(@"^(?:f[1-9]|f1[0-2])$");


    private PreviewKeyDownEventArgs lastHandledEvent;


    public virtual void OnKeyDown(object sender, PreviewKeyDownEventArgs e)

    {

        if (e == lastHandledEvent)

        {

            return;

        }

        OnKeyDown(e.KeyCode);

        lastHandledEvent = e;

    }


    protected override Keys GetKey(string KeysName)

    {

        if (LetterKeysNamePattern.IsMatch(KeysName))

        {

            return ParseKey(KeysName.ToUpper());

        }

        if (NumberKeysNamePattern.IsMatch(KeysName))

        {

            return ParseKey("D" + KeysName);

        }

        if (KeyspadNumberKeysNamePattern.IsMatch(KeysName))

        {

            return ParseKey(KeysName.Replace("kp_", "NumPad"));

        }

        if (FunctionKeysNamePattern.IsMatch(KeysName))

        {

            return ParseKey(KeysName.ToUpper());

        }

        switch (KeysName)

        {

            case "left":

            case "L":

            case "←":

                return Keys.Left;

            case "up":

            case "U":

            case "↑":

                return Keys.Up;

            case "right":

            case "R":

            case "→":

                return Keys.Right;

            case "down":

            case "D":

            case "↓":

                return Keys.Down;

            case "backspace":

                return Keys.Back;

            case "tab":

                return Keys.Tab;

            case "enter":

                return Keys.Enter;

            case "return":

                return Keys.Return;

            case "shift":

            case "?":

                return Keys.LShiftKey;

            case "control":

            case "ctrl":

            case "^":

                return Keys.LControlKey;

            case "alt":

            case "option":

            case "?":

                return Keys.Alt;

            case "command":

            case "?":

                return Keys.LWin;

            case "pause":

                return Keys.Pause;

            case "capslock":

                return Keys.CapsLock;

            case "esc":

                return Keys.Escape;

            case "space":

                return Keys.Space;

            case "pageup":

                return Keys.PageUp;

            case "pagedown":

                return Keys.PageDown;

            case "end":

                return Keys.End;

            case "home":

                return Keys.Home;

            case "insert":

                return Keys.Insert;

            case "delete":

                return Keys.Delete;

            case "equal":

            case "=":

                return Keys.Oemplus;

            case "comma":

            case ",":

                return Keys.Oemcomma;

            case "minus":

            case "-":

                return Keys.OemMinus;

            case "period":

            case ".":

                return Keys.OemPeriod;

            case "kp_multiply":

                return Keys.Multiply;

            case "kp_plus":

                return Keys.Add;

            case "kp_minus":

                return Keys.Subtract;

            case "kp_decimal":

                return Keys.Decimal;

            case "kp_divide":

                return Keys.Divide;

        }

        throw new ArgumentException(String.Format("Could not map Keys named '{0}'.", KeysName));

    }


    private static Keys ParseKey(string KeysName)

    {

        return (Keys)Enum.Parse(typeof(Keys), KeysName);

    }

}

然后,只要將代碼放入表單加載處理程序中,它就會(huì)按預(yù)期工作:


protected override void OnLoad(EventArgs e)

{

    var cheet = new Cheet();

    PreviewKeyDown += cheet.OnKeyDown;

    cheet.Map("c h e a t", () => { MessageBox.Show("Voilà!"); });


    base.OnLoad(e);

}


查看完整回答
反對(duì) 回復(fù) 2023-08-20
?
PIPIONE

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超9個(gè)贊

更新(因?yàn)槟褜㈠e(cuò)誤輸出添加到問(wèn)題中):

預(yù)期類、結(jié)構(gòu)或接口成員聲明類型中的標(biāo)記“+=”無(wú)效

你不能只將 C# 代碼放在類的頂層,你必須遵循一個(gè)最小的結(jié)構(gòu)。您可以將此類代碼放置在類的構(gòu)造函數(shù)方法或其他方法或靜態(tài)初始化塊中(如果您僅在代碼中引用靜態(tài)內(nèi)容)

下次更新(新錯(cuò)誤之后):

使用泛型類型“Cheet”需要 1 個(gè)類型參數(shù)

您正在使用通用包而不是 Wpf 包:

public?class?Cheet?:?Cheet<Key>,?ICheet

很不幸我認(rèn)為他們使用相同的類名

查看完整回答
反對(duì) 回復(fù) 2023-08-20
?
繁星coding

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超4個(gè)贊

存儲(chǔ)庫(kù)中有一個(gè) WPF 演示應(yīng)用程序,您可以在 Window 構(gòu)造函數(shù)中進(jìn)行初始化:


public MainWindow()

{

    var cheet = new Cheet();

    PreviewKeyDown += cheet.OnKeyDown;


    cheet.Map("↑ ↑ ↓ ↓ ← → ← → b a", () => { WriteLine("Voilà!"); });


    cheet.Map("i d d q d", () => {

        WriteLine("god mode enabled");

    });

    [etc.]

因此,您可以使用 處理PreviewKeyDown事件cheet.OnKeyDown,并且OnKeyDownCheet 中可能會(huì)循環(huán)遍歷其映射并尋找合適的映射。


我設(shè)置了一個(gè)測(cè)試 WinForms 項(xiàng)目并添加了 Cheet.NET,如果您想將它與 WinForms 一起使用,您似乎需要做一些工作。


Cheet.Core有一個(gè)Cheet<T>類,但它是抽象的。看起來(lái)T是打算成為“鑰匙”類型的。Cheet.Wpf 庫(kù)有一個(gè)Cheet繼承自 的類Cheet<Key>,使用 WPFKey類型。


看來(lái)您需要?jiǎng)?chuàng)建自己的Cheet類(很可能)繼承自Cheet<System.Windows.Forms.Keys>.


我想現(xiàn)在的問(wèn)題是哪個(gè)工作量更大:為 WinForms 實(shí)現(xiàn) Cheet,還是在 WPF 中重新開(kāi)始您的項(xiàng)目


查看完整回答
反對(duì) 回復(fù) 2023-08-20
  • 3 回答
  • 0 關(guān)注
  • 175 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)