Register for your free account! | Forgot your password?

Go Back   elitepvpers Coders Den .NET Languages
You last visited: Today at 16:38

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



C# String zum Key

Discussion on C# String zum Key within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1
 
gokay22's Avatar
 
elite*gold: 0
Join Date: May 2007
Posts: 187
Received Thanks: 76
C# String zum Key

Hallo liebe User,
Ich habe seit langer Zeit ein Problem das mich ne Weile beschäftigt.
Es geht um Hotkeys und Strings..

Was ich machen will:

Ich habe jetzt diesen Code:


Code:
        UserActivityHook lisa = new UserActivityHook(false, true);
        Keys[] hotkeys;

        public MainForm()
        {
            InitializeComponent();

            hotkeys = new Keys[80];
            lisa.KeyDown += new KeyEventHandler(lisa_KeyDown);
        }



        private void LadenButton_Click(object sender, EventArgs e)
        {

            XmlDocument configdoc = new XmlDocument();
            configdoc.Load("Config.xml");

            XmlNode hottaste = configdoc.SelectSingleNode("/BindConfig/Hotkey0");
            hotkeys[0] = Keys.None; //Hier soll der Convert von String zum Key stattfinden
        }


        private void SpeichernButton_Click_1(object sender, EventArgs e)
        {

            XmlTextWriter keybinderconfig = new XmlTextWriter("Config.xml", System.Text.Encoding.UTF8);
            keybinderconfig.Formatting = Formatting.Indented;
            keybinderconfig.WriteStartDocument(false);

            keybinderconfig.WriteStartElement("BindConfig");
            keybinderconfig.WriteElementString("HotKey0", hotkeys[0].ToString());
       }
Was ich versucht habe beim Laden war:

hotkeys[0] = hottaste.InnerText; //wobei hier nur der String geladen wird und zu einem error kommt. Ich will jedoch das er den String in den Key konvertiert


Danke im Vorraus...
gokay22 is offline  
Old   #2

 
x]vIrus[x's Avatar
 
elite*gold: 37
Join Date: Apr 2004
Posts: 2,154
Received Thanks: 250
das selbe problem hatte ich auch schonmal, ich habe mir dann nen kleinen parser geschrieben:

Code:
        public static Shortcut parseShortcut(string name)
        {
            int c = 0;
            try
            {
                c = int.Parse(name);
                return (Shortcut)c;
            }

            catch (Exception) { }
            name = name.Replace("Ctrl", "Control");
            name = name.Replace("Bkspc", "Back");

            string[] parts = name.Split('+');

            for (int i = 0; i < parts.Length; i++)
            {
                parts[i] = Regex.Replace(parts[i], "[0-9]", "D" + parts[i]);
                c += (int)Enum.Parse(typeof(Keys), parts[i]);
            }

            return (Shortcut)c;
        }
input muss z.b. so aussehen:
parseShortcut("Control+Alt+B");
oder parseShortcut("Alt+F4");

^^
x]vIrus[x is offline  
Thanks
1 User
Old   #3

 
x]vIrus[x's Avatar
 
elite*gold: 37
Join Date: Apr 2004
Posts: 2,154
Received Thanks: 250
ein hotkey is ein Shortcut

und hier das umgekehrte:
Code:
        public static string getShortcutName(Shortcut shortcut)
        {
            Array a = Enum.GetValues(typeof(Keys));
            string s = "";

            for (int i = a.Length; i > 0; i--)
            {
                Keys k = (Keys)a.GetValue(i - 1);
                if (((uint)k & (uint)shortcut) == (uint)k)
                {
                    string key = k.ToString();

                    if (shortcut == 0)
                    {
                        i = 0;
                        if (s.EndsWith("+")) s = s.Substring(0, s.Length - 1);
                        else if (s.Length == 0) s = "None";
                    }
                    else
                    {
                        key = Regex.Replace(key, "D[0-9]", Regex.Match(key, "D([0-9])").Groups[1].ToString());
                        s += key + "+";
                    }
                    shortcut = (Shortcut)((uint)shortcut - (uint)k);
                }
            }

            return s;
        }
x]vIrus[x is offline  
Thanks
1 User
Old   #4
 
gokay22's Avatar
 
elite*gold: 0
Join Date: May 2007
Posts: 187
Received Thanks: 76
Du meinst ich kann dann einfach so das übernehmen: ?
hotkeys[0] = parseShortcut(hottaste.InnerText);
gokay22 is offline  
Old   #5

 
x]vIrus[x's Avatar
 
elite*gold: 37
Join Date: Apr 2004
Posts: 2,154
Received Thanks: 250
solange es kein shortcut sein soll kannst du auch einfach
Code:
hotkeys[0] = (Keys)Enum.Parse(typeof(Keys), hottaste.InnerText);
nehmen

mfg
x]vIrus[x is offline  
Thanks
1 User
Old   #6
 
gokay22's Avatar
 
elite*gold: 0
Join Date: May 2007
Posts: 187
Received Thanks: 76
Kriege folgenden Error nach dem LadeButton drücken:
Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
gokay22 is offline  
Old   #7

 
x]vIrus[x's Avatar
 
elite*gold: 37
Join Date: Apr 2004
Posts: 2,154
Received Thanks: 250
solche fehler solltest du selbst lösen können check ma ob hottaste.innertext null is oder net, ich bin grad net dahaim, deshalb kann ich nicht wirklich testen/debuggen, aber beim debuggen müsstest du herausfinden können was falsch ist,...

mfg
x]vIrus[x is offline  
Thanks
1 User
Old   #8
 
gokay22's Avatar
 
elite*gold: 0
Join Date: May 2007
Posts: 187
Received Thanks: 76
Klappt perfekt
Danke dir nochmal ^^ Hast für jeden Post ein Thanks bekommen
gokay22 is offline  
Reply


Similar Threads Similar Threads
String.au3
09/11/2010 - AutoIt - 2 Replies
Hey, hat jemand die Datei für mich? Ich finde im Internet nichts (ich hoffe ich habe nichts übersehn) Mfg
[C++]Dev C++ string to int
08/06/2010 - C/C++ - 25 Replies
Schonwieder ich :P Also ich versuchs ma gut zu beschreiben. Ich habe nen string in dem steht 1 und bevor einer fragt warum ich nicht direkt int benutzte es würde dan nicht funktioniern. Also ich möchte den string in dem 1 steht in eine int variable umwandeln und danach irgendwan wieder zurück wie schaffe ich das? mit atoi habe ich es nicht hingekriegt und auch nicht mit strtoint
Englische String.txt?
05/27/2010 - Metin2 Private Server - 0 Replies
Gibt es eine Englische String.txt? Also wo alles englisch ist
[HELP]Wrong String
09/14/2009 - Dekaron Private Server - 21 Replies
http://www.dekaron-legendz.com/Photos/bug1.jpg well this is my Summy skill Book . . and i cant see the string name for that skill book . any idea how to change the name to Ex. " Fury Explosion " thanks .
Getting ID String for RPE
07/15/2009 - Ragnarok Online - 0 Replies
Is there any way for getting ID String for account ID than using openkore ? openkore doesn't work on my server, I need to get the String ID so I can use RPE filter. Does anyone know the solution for this ?



All times are GMT +2. The time now is 16:39.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.