Guest User

Untitled

a guest
Jan 17th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. public class KeyConverter {
  2. //All conversions are stored in this dictionary.
  3. private Dictionary<Keys, Keys> conversions = new Dictionary<Keys, Keys>();
  4.  
  5. public KeyConverter() {
  6. //this conversion will convert every Ctrl+C signal into Ctrl+V
  7. conversions.Add(Keys.C | Keys.Control, Keys.V | Keys.Control);
  8. }
  9.  
  10. public Keys Convert(Keys keys) {
  11. if (conversions.ContainsKey(keys))
  12. return conversions[keys];
  13. else
  14. return keys; //return the input if no conversion is available
  15. }
  16. }
  17.  
  18. [DllImport("user32.dll")]
  19. public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
  20.  
  21. public void SendKey(Keys keys){
  22. foreach(Keys key in Enum.GetValues(typeof(Keys)))
  23. if(keys.HasFlag(key))
  24. keybd_event((byte)key, 0, 0, 0); //press key
  25. foreach(Keys key in Enum.GetValues(typeof(Keys)))
  26. if(keys.HasFlag(key))
  27. keybd_event((byte)key, 0, 0x2, 0); // release key
  28. }
Add Comment
Please, Sign In to add comment