示例#1
0
        public static bool activateN64Emulator()
        {
            // retrieve Notepad main window handle
            IntPtr         hWnd = InterceptKeys.FindWindow("Project64 2.3.2.202", null);
            InputSimulator sim  = new InputSimulator();

            if (!hWnd.Equals(IntPtr.Zero) && hWnd == InterceptKeys.GetForegroundWindow())
            {
                //we dont want to block user to make focus on another window
                //InterceptKeys.SetForegroundWindow(hWnd);

                //InterceptKeys.SetForegroundWindow(hWnd); //Activate Handle By Process
                // InterceptKeys.ShowWindow(hWnd, InterceptKeys.SW_RESTORE); //Maximizes Window in case it was minimized.
                //sim.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.RETURN);
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#2
0
        /// <summary>
        /// Callback method to report the intercepted input key
        /// </summary>
        /// <param name="nCode"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        private static IntPtr HookKeyCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            //when key is pressed
            if (nCode >= 0 && wParam == (IntPtr)InterceptKeys.WM_KEYDOWN)
            {
                int vkCode = Marshal.ReadInt32(lParam);

                //convert key to One-Hot Vector
                m_OutputLabel = InputKeyToHotVector((Keys)vkCode);

                //
                if ((Keys)vkCode == Keys.W)
                {
                    m_WPressed = true;
                }
                if ((Keys)vkCode == Keys.S)
                {
                    m_SPressed = true;
                }
            }
            //control  when W and S is released
            if (nCode >= 0 && wParam == (IntPtr)InterceptKeys.WM_KEYUP)
            {
                int vkCode = Marshal.ReadInt32(lParam);
                if ((Keys)vkCode == Keys.W)
                {
                    m_WPressed = false;
                }
                if ((Keys)vkCode == Keys.S)
                {
                    m_SPressed = false;
                }
            }

            return(InterceptKeys.CallNextHookEx(_hookID, nCode, wParam, lParam));
        }
示例#3
0
 /// <summary>
 /// Intercepts the Keys in put and process them
 /// </summary>
 private static void CaptureGameControlKeys()
 {
     _hookID = InterceptKeys.SetHook(_proc);
     Application.Run();
     InterceptKeys.UnhookWindowsHookEx(_hookID);
 }