Example #1
0
        private IntPtr captureKey(int nCode, IntPtr wp, IntPtr lp)
        {
            if (nCode >= 0)
            {
                theKey = (KeyHook)Marshal.PtrToStructure(lp, typeof(KeyHook));
                // Keyboard Hook Time /////////////////////////////////////////////////////////////////////////////////////////

                if (theKey.flags < 128 && (int)theKey.Key != (int)Keys.Return)
                {
                    _pressedKey = theKey.Key;

                    _pressedKeyName = MainForm.VirtualKeyName(_pressedKey);

                    lblKeyName.Text    = _pressedKeyName; //+ " " + _pressedKey.ToString(); //+ " " + nonVirtualKey; //MainForm.KeyName(theKey.Key)
                    btnAccept.Enabled  = true;
                    this.ActiveControl = btnAccept;
                }

                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
            }
            return(CallNextHookEx(ptrHook, nCode, wp, lp));
        }
Example #2
0
        private IntPtr captureKey(int nCode, IntPtr wp, IntPtr lp)
        {
            //using (StreamWriter sw = File.AppendText("keys.log"))
            //{
            //sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "  nCode=" + nCode);

            if (nCode >= 0)     //(proc != null && nCode >= 0)
            {
                theKey = (KeyHook)Marshal.PtrToStructure(lp, typeof(KeyHook));
                // Keyboard Hook Time /////////////////////////////////////////////////////////////////////////////////////////

                //if (theKey.flags < 128) MessageBox.Show(theKey.key.ToString() + "\n" + ((int)theKey.key).ToString());

                //sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "  key=" + (int)theKey.Key + " code=" + theKey.Code + " flags=" + theKey.flags + " extra=" + theKey.extra);

                if (((IList <Keys>)catchKeys).Contains(theKey.Key) && hotKeys)
                {
                    if (theKey.flags < 128 && currentKey != theKey.Key)
                    {
                        TimerReset();
                        currentKey = theKey.Key;
                        UpdateMem();
                        TimerHoldKey.Start();
                    }
                    else if (theKey.flags >= 128)
                    {
                        TimerReset();
                        currentKey = Keys.None;
                        SaveSettings();
                    }
                }

                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
            }
            return(CallNextHookEx(ptrHook, nCode, wp, lp));

            //}
        }