示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = button2.Enabled = false;

            pressDelay   = new BinaryWriter(File.Open("pressDelay", FileMode.Append, FileAccess.Write, FileShare.None));
            nextKeyDelay = new BinaryWriter(File.Open("nextKeyDelay", FileMode.Append, FileAccess.Write, FileShare.None));

            Hooker.s_KeyDown += _keyDown;
            Hooker.s_KeyUp   += _keyUp;
            Hooker.HookKeyboard();
            hooked = true;
        }
示例#2
0
        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (hooked)
            {
                t.Abort();
                Hooker.UnhookKeyboard();
                Hooker.UnhookMouse();
                //pressDelay.Close();//DEBUG
                //nextKeyDelay.Close();
                hooked = false;

                WindowMonitor.StopMonitorForeground();

                InputEventDispatcher.DisposeIt();
                Application.Exit();
            }
        }
示例#3
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            LoadAllSettings(); //settings only.

            validCondition = (newName) => { return(!_macroPages.Any((page) => page.name.Equals(newName))); };

            _macroPages = new List <MacroPage>();
            _macroPages.Add(new MacroPage("Default", new List <Macro>()));

            LoadMacros();
            CompileAll();
            DisplayCurrentMacroPage();

            UpdateOSD(_macroPages[0].name, 0);
            if (settings._opOSDEnable)
            {
                ShowOSD();
            }


            _frmOsd.FollowTarget = settings._opOSDTarget;
            SetOSDLocked(settings._opOSDLock);

            WindowMonitor.BeginMonitorForeground();

            //trayIcon.ShowBalloonTip(3000, "KeyReplace", "KeyReplace is now running.", ToolTipIcon.Info);

            t = new Thread((ThreadStart) delegate
            {
                Hooker.s_KeyDown += _keyDown;
                Hooker.s_KeyUp   += _keyUp;
                Hooker.HookKeyboard();
                Application.Run();
            }); //we run the keyboard thread on a seperate thread with a message loop
                // courtesy: https://stackoverflow.com/questions/25502960/install-low-level-mouse-hook-in-different-thread


            t.Start();

            Hooker.s_MouseDown += _mouseDown;
            Hooker.s_MouseUp   += _mouseUp;
            Hooker.HookMouse();
            hooked = true;
        }
示例#4
0
        /// <summary>
        /// renders a keycode into a human readable string.
        /// </summary>
        public static string parsekeydown(int vk)
        {
            bool caps  = (((ushort)Hooker.GetKeyState(0x14)) & 0xffff) != 0;
            bool shift = Hooker.IsKeyPushedDown(Keys.ShiftKey);

            //33-47, 58-64, 91-96, 123-126
            if (vk >= 65 && vk <= 90)
            {
                //uppercase only if one or the other, but not both.
                return((shift ^ caps) ?
                       new string(new char[] { (char)vk }) :
                       new string(new char[] { (char)vk }).ToLower());
            }
            if (vk > 95 && vk < 106)
            {
                return((vk - 96).ToString());                     //numberpad keys
            }
            if (vk >= 112 && vk <= 135)
            {
                return("[F" + (vk - 111).ToString() + "]");                         //function keys
            }
            if (shift && shiftKeys.ContainsKey(vk))
            {
                return(shiftKeys[vk]);
            }
            if (downKeys.ContainsKey(vk))
            {
                return(downKeys[vk]);
            }
            if (vk >= 48 && vk <= 57)
            {
                return(new string((char)vk, 1)); //top number keys
            }
            else
            {
                return("[vk" + Convert.ToString(vk) + "]");
            }
        }