How to change the output of a keyboard press?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Karl Johansson
    New Member
    • Mar 2011
    • 2

    How to change the output of a keyboard press?

    Hey there! I'm preparing a 1st of april- joke for my roomate and decided I wanted to create a little hidden program that would take control of the user's keyboard.

    So for example, when you press on 'a' you don't really get an 'a' on the screen, rather its supposed to be changed to a random letter.

    So far: I have successefully hooked the keyboard to my application and I can read all keystrokes that are pressed. But i'm unable to change the "resulted" keystroke...

    Uhm, sorry if i havnt given enough information, if so. Please let me know!
  • Sfreak
    New Member
    • Mar 2010
    • 64

    #2
    Karl,

    The following code may help you

    On event KeyDown
    Code:
     
    if (e.KeyCode == Keys.Enter)
    {
        SendKeys.Send("{TAB}");
    }
    Where tab is the name of the key
    This case when the user hits Enter i send TAB

    Comment

    • Karl Johansson
      New Member
      • Mar 2011
      • 2

      #3
      Thank you for your reply. I'm sorry It seems I have not supplied with enough information.
      --

      I want it to have "Full" control of all running applications and replacing the input key with a new key.

      What I want to do is kinda like:

      Code:
      // this is just a pseudo code
      // ---
      // just a list of pressed keys
      // GetPressedKeys() Can be iterated with a function using like GetAsyncKeyState();
      var pressedKeys = GetPressedKeys(); 
      foreach(var pKey in pressedKeys)
      {
          // Disables the output/Ignores the keypress by
          // any running processes.
          pKey.Cancel = true; 
          
          var hwnd = GetForegroundWindow();
          var randomKey = GetRandomKey();
          KeyboardUtility.SendKey(hwnd, randomKey);
      }
      Anyone aware of how this could be possible?
      Last edited by Karl Johansson; Mar 31 '11, 12:27 PM. Reason: missed out information.

      Comment

      Working...