Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class KeyConverter {
- //All conversions are stored in this dictionary.
- private Dictionary<Keys, Keys> conversions = new Dictionary<Keys, Keys>();
- public KeyConverter() {
- //this conversion will convert every Ctrl+C signal into Ctrl+V
- conversions.Add(Keys.C | Keys.Control, Keys.V | Keys.Control);
- }
- public Keys Convert(Keys keys) {
- if (conversions.ContainsKey(keys))
- return conversions[keys];
- else
- return keys; //return the input if no conversion is available
- }
- }
- [DllImport("user32.dll")]
- public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
- public void SendKey(Keys keys){
- foreach(Keys key in Enum.GetValues(typeof(Keys)))
- if(keys.HasFlag(key))
- keybd_event((byte)key, 0, 0, 0); //press key
- foreach(Keys key in Enum.GetValues(typeof(Keys)))
- if(keys.HasFlag(key))
- keybd_event((byte)key, 0, 0x2, 0); // release key
- }
Add Comment
Please, Sign In to add comment