[C#] Keyboard Simulation - Translating non characters to System.Windows.Forms.Keys menu

User Tag List

Results 1 to 5 of 5
  1. #1
    Tanaris4's Avatar Contributor Authenticator enabled
    Reputation
    148
    Join Date
    Oct 2008
    Posts
    646
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [C#] Keyboard Simulation - Translating non characters to System.Windows.Forms.Keys

    All-

    Had a quick question that I feel is straightforward but I'm missing something basic.

    Basically I'm sending key commands using postmessage:
    Code:
    [DllImport("user32.dll")]
    public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, UIntPtr lParam);
    
    public static void KeyDown2(System.Windows.Forms.Keys Key)
    {
        PostMessage(Memory.MyHandle, WM_KEYDOWN, new IntPtr((int)(Key & Keys.KeyCode)), new UIntPtr(0));
    }
    
    public static void KeyUp2(System.Windows.Forms.Keys Key)
    {
        PostMessage(Memory.MyHandle, WM_KEYUP, new IntPtr((int)(Key & Keys.KeyCode)), new UIntPtr(0));
    }
    And was wondering how I can convert keys such as [, ], <, >, â, ƒ etc... to the appropriate Key based on the user's keyboard.

    Basically I'm traversing the user's bindings + I'm getting hung up on special non 0-9, A-Z characters.

    Any help/pointers would be greatly appreciated! I've seen so many posts on stackoverflow and I feel like none are actually relevant to this. It talks about using the KeysConverter class but that doesn't give the correct Keys type back.

    This doesn't work:
    Code:
    KeysConverter kc = new KeysConverter();
    Key = (Keys)kc.ConvertFromString("â");
    Edit: This is the closest thing I've found, but doesn't seem to account for keyboard differences: http://stackoverflow.com/questions/2...er-to-key-code

    Thanks in advance!
    ~ Tanaris
    Last edited by Tanaris4; 11-13-2012 at 08:09 PM.
    https://tanaris4.com

    [C#] Keyboard Simulation - Translating non characters to System.Windows.Forms.Keys
  2. #2
    ~Unknown~'s Avatar Contributor
    Reputation
    193
    Join Date
    Jan 2009
    Posts
    211
    Thanks G/R
    0/5
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you attempt to use the MapVirtualKeyEx function that was mentioned in that post?

    dwhkl [in, out, optional]
    Type: HKL

    Input locale identifier to use for translating the specified code. This parameter can be any input locale identifier previously returned by the LoadKeyboardLayout function.

    An application can use MapVirtualKeyEx to translate scan codes to the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU, and vice versa

    Seems like given a specific KeyboardLayout, you can map a character that you read to a specific VirtualKey.


    Am I assuming you are trying to read the users keybinds and use them for bot logic instead of rebinding your own? seems like a lot trouble just to preserve keybinds :P

  3. #3
    Tanaris4's Avatar Contributor Authenticator enabled
    Reputation
    148
    Join Date
    Oct 2008
    Posts
    646
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea people just complain a lot about having to change their bindings. At a minimum I can just require it be A-Z0-9 w/shift/alt/control combinations. But I just would like it to be complete

    Edit: This is pretty terrible, I really don't see a solution that would work for accented characters. But for converting keys like [] you can just use:

    Code:
            private static System.Windows.Input.Key ResolveKey(char charToResolve)
            {
                return System.Windows.Input.KeyInterop.KeyFromVirtualKey(VkKeyScan(charToResolve));
            }
    
            public static Keys GetKeysForChar(char charToResolve)
            {
                System.Windows.Input.Key wpfKey = ResolveKey(charToResolve);
                Keys K = (Keys)System.Windows.Input.KeyInterop.VirtualKeyFromKey(wpfKey);
                return K;
            }
    Last edited by Tanaris4; 11-13-2012 at 10:04 PM.
    https://tanaris4.com

  4. #4
    ~Unknown~'s Avatar Contributor
    Reputation
    193
    Join Date
    Jan 2009
    Posts
    211
    Thanks G/R
    0/5
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I didn't realize there are keyboards that have accented letters, but I guess for those in other countries it is more common. It seems according to Key Enumeration (System.Windows.Input) most keyboards conform to the typical ASCII character codes, but accented are from Unicode I assume. I know the keybd_event win api will take into account a 16bit Unicode offset for those types of things. I would see if you can find something similar to how it works. Otherwise....buy a keyboard and check what happens when you press keys? lol

  5. #5
    Bananenbrot's Avatar Contributor
    Reputation
    153
    Join Date
    Nov 2009
    Posts
    384
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not exactly sure if that's working, but see http://github.com/Bananenbrot/Keyboa...yCodeMapper.cs and http://github.com/Bananenbrot/Keyboa...ingKeyboard.cs.
    I've to admit hat I'm not into keyboard stuff anymore, but iirc if there are modifiers involved, messaging won't work because they are posted in the wrong order or sth.
    But since you are talking about internationalization, there is hope that there aren't any modifiers involved...

Similar Threads

  1. [Trading] LoL (all Champs) + SWtoR (End Game Character) Accounts for HS Beta Key.
    By Technogandalf in forum Hearthstone Buy Sell Trade
    Replies: 1
    Last Post: 10-03-2013, 09:18 PM
  2. [Diary/Essay/Compendium] Keyboard simulation
    By Bananenbrot in forum WoW Memory Editing
    Replies: 13
    Last Post: 11-15-2012, 02:31 PM
  3. [Trading] Offering character-powerup package for WOTLK key
    By Ghostpoke in forum World of Warcraft Buy Sell Trade
    Replies: 2
    Last Post: 07-08-2010, 10:03 AM
  4. Translation System
    By kevin08330 in forum Suggestions
    Replies: 16
    Last Post: 07-20-2009, 03:20 PM
  5. BC Character on non BC Account
    By n3gro in forum World of Warcraft General
    Replies: 13
    Last Post: 05-31-2009, 12:34 AM
All times are GMT -5. The time now is 11:16 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search