469,301 Members | 2,282 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,301 developers. It's quick & easy.

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!
Mar 27 '11 #1
2 3364
Sfreak
64
Karl,

The following code may help you

On event KeyDown
Expand|Select|Wrap|Line Numbers
  1.  
  2. if (e.KeyCode == Keys.Enter)
  3. {
  4.     SendKeys.Send("{TAB}");
  5. }
Where tab is the name of the key
This case when the user hits Enter i send TAB
Mar 30 '11 #2
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:

Expand|Select|Wrap|Line Numbers
  1. // this is just a pseudo code
  2. // ---
  3. // just a list of pressed keys
  4. // GetPressedKeys() Can be iterated with a function using like GetAsyncKeyState();
  5. var pressedKeys = GetPressedKeys(); 
  6. foreach(var pKey in pressedKeys)
  7. {
  8.     // Disables the output/Ignores the keypress by
  9.     // any running processes.
  10.     pKey.Cancel = true; 
  11.  
  12.     var hwnd = GetForegroundWindow();
  13.     var randomKey = GetRandomKey();
  14.     KeyboardUtility.SendKey(hwnd, randomKey);
  15. }
  16.  
Anyone aware of how this could be possible?
Mar 31 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

13 posts views Thread by FlickChick | last post: by
13 posts views Thread by Ole Hanson | last post: by
2 posts views Thread by Gwl | last post: by
1 post views Thread by Lacka | last post: by
2 posts views Thread by ahmed ahmed | last post: by
reply views Thread by dotnettester | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.