Interacting with keyboard input.

This is a discussion on Interacting with keyboard input. within the C# Programming forums, part of the General Programming Boards category; Hi! I tried to interact with the user's keyboard input in order to eg. replace the letter 'a' with '4' ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    244

    Interacting with keyboard input.

    Hi!
    I tried to interact with the user's keyboard input in order to eg. replace the letter 'a' with '4' and 'e' with '3'. You know what I'm up to. I want to make a leetspeak translator so you can chat without having to write something like this.

    i managed to grab the keyboard input just like a keylogger and send a keystroke like backspace and then the letter. but that doesn't work.

    Do you have any idea how to do this?
    thanks

  2. #2
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    never mind. after days of trying i got it to work.

    does anyone know how to convert a System.Windows.Forms.Keys to char?

  3. #3
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    Code:
    Keys k = Keys.A;
    char c = (char)k;

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    i know but this fails at things like "" or ""...
    how do i really convert them?

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    alright, grabbed that code and used the scancode parameter, too:
    Code:
    [DllImportAttribute("user32.dll")]
    		public static extern int ToAscii(int uVirtKey, int uScanCode, byte[] lpbKeyState, byte[] lpChar, int uFlags);
    		[DllImportAttribute("user32.dll")]
    		public static extern int GetKeyboardState(byte[] pbKeyState);
    
    		public static char GetAsciiCharacter(int uVirtKey, int uScanCode)
    		{
    			byte[] lpKeyState = new byte[256];
    			GetKeyboardState(lpKeyState);
    			byte[] lpChar = new byte[2];
    			if (ToAscii(uVirtKey, uScanCode, lpKeyState, lpChar, 0) == 1)
    			{
    				return (char)lpChar[0];
    			}
    			else
    			{
    				return new char();
    			}
    		}
    oh, did i forget to mention i solved it? i did.
    Last edited by Devils Child; 06-05-2009 at 07:15 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help using inline assembly for keyboard input
    By sleventeen in forum C Programming
    Replies: 7
    Last Post: 05-10-2009, 02:31 AM
  2. Keyboard Input
    By CaliJoe in forum C++ Programming
    Replies: 3
    Last Post: 05-08-2009, 10:51 AM
  3. Keyboard input in a Dialog
    By ksarkar in forum C++ Programming
    Replies: 1
    Last Post: 05-20-2005, 06:39 AM
  4. Intercepting keyboard input
    By EvBladeRunnervE in forum Windows Programming
    Replies: 3
    Last Post: 01-08-2004, 09:03 AM
  5. Need help with Console Keyboard Input
    By pawelx2 in forum Game Programming
    Replies: 5
    Last Post: 05-31-2002, 12:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21