private void OnEnable() { RawInputWindowProcedure.Instance.ReceiveRawInput += OnReceiveRawInput; #if UNITY_EDITOR Debug.Log("RawInputDevice.RegisterDevice was skipped in editor, readWhenBackground = " + readWhenBackground); #else RawInputDevice.RegisterDevice( HidUsageAndPage.Mouse, readWhenBackground ? RawInputDeviceFlags.InputSink : RawInputDeviceFlags.None, WinApiUtils.GetUnityWindowHandle() ); #endif }
/// <summary> /// Force to stop window hook. Normally you do not have to call it directly. /// </summary> public void DisableWindowHook() { // Avoid to assign invalid window procedure. if (_oldWndProcPtr == IntPtr.Zero) { return; } // Reset Window Procedure to original one. #if !UNITY_EDITOR SetWindowLongPtr(WinApiUtils.GetUnityWindowHandle(), GWLP_WNDPROC, _oldWndProcPtr); #endif _oldWndProcPtr = IntPtr.Zero; _newWndProcPtr = IntPtr.Zero; _newWndProc = null; _isWindowHooked = false; _receiveRawInput = null; }
private void EnableWindowHook() { if (_isWindowHooked) { return; } // Hook window procedure _newWndProc = WndProc; _newWndProcPtr = Marshal.GetFunctionPointerForDelegate(_newWndProc); #if UNITY_EDITOR Debug.Log("Do not start RawInputWindowProcedure, because function '" + nameof(SetWindowLongPtr) + "' might leads editor crash."); Debug.Log( $"{nameof(_newWndProcPtr)} remains to IntPtr.Zero, and param {nameof(GWLP_WNDPROC)} is not used."); #else _oldWndProcPtr = SetWindowLongPtr( WinApiUtils.GetUnityWindowHandle(), GWLP_WNDPROC, _newWndProcPtr ); #endif _isWindowHooked = true; }