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)); }
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 (hotKeys && ((IList <Keys>)catchKeys).Contains(theKey.Key)) { 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)); //} }