/// <summary> /// Register to get a callback whenever the specified KeyCodeEventPair input is detected /// </summary> public KeyboardRegistration RegisterKeyEvent(KeyCodeEventPair keycodeEvent, KeyboardCallback callback) { if (!registeredCallbacks.ContainsKey(keycodeEvent)) { registeredCallbacks.Add(keycodeEvent, new List <KeyboardCallback>()); } // Don't register the same callback more than once List <KeyboardCallback> callbackList = registeredCallbacks[keycodeEvent]; for (int i = 0; i < callbackList.Count; i++) { if (callbackList[i] == callback) { // Duplicate Debug.LogError("Ignoring duplicate keyboard callback."); return(null); } } callbackList.Add(callback); // return a registration object, which must be referenced until it's disposed to unregister return(new KeyboardRegistration(keycodeEvent, callback)); }
public void LaunchPlayStore() { #if !UNITY_ANDROID || UNITY_EDITOR Debug.LogError("GvrKeyboardIntent requires the Android runtime environment"); #else KeyboardCallback cb = new KeyboardCallback(); keyboardFragment.Call("launchPlayStore", cb); #endif // !UNITY_ANDROID || UNITY_EDITOR }
public static void init() { keyPressedCallback = null; keyReleasedCallback = null; padMovedCallback = null; buttonPressedCallback = null; buttonReleasedCallback = null; mouseMovedCallback = null; mousePressedCallback = null; mouseReleasedCallback = null; }
/// <summary> /// Creates global keyboard listener. /// </summary> public KeyboardListener() { // We have to store the HookCallback, so that it is not garbage collected runtime _hookedKeyboardHook = LowLevelKeyboardProc; // Set the hook _hookId = SetHook(_hookedKeyboardHook); // Assign the asynchronous callback event _hookedKeyboardCallback = KeyboardListener_KeyboardCallbackAsync; }
public void Connect() { if (IsConnected) { throw new InvalidOperationException("The keyboard hook is already connected."); } _hookedKeyboardHook = LowLevelKeyboardProc; _hookId = SetHook(_hookedKeyboardHook); _hookedKeyboardCallback = KeyboardListener_KeyboardCallbackAsync; IsConnected = true; }
/// <summary> /// Creates global keyboard listener. /// </summary> public KeyboardListener() { // Dispatcher thread handling the KeyDown/KeyUp events. this.dispatcher = Dispatcher.CurrentDispatcher; // We have to store the LowLevelKeyboardProc, so that it is not garbage collected runtime hookedLowLevelKeyboardProc = (User32.LowLevelKeyboardProc)LowLevelKeyboardProc; // Set the hook hookId = SetHook(hookedLowLevelKeyboardProc); // Assign the hronous callback event hookedKeyboardCallback = new KeyboardCallback(KeyboardListener_KeyboardCallback); }
public void Disconnect() { if (!IsConnected) { throw new InvalidOperationException("The keyboard hook is already disconnected."); } UnhookWindowsHookEx(_hookId); _hookedKeyboardHook = null; _hookedKeyboardCallback = null; _hookId = default(IntPtr); }
public DriverReplacement(Guid deviceGuid, string devicePath, RemoteCallback remoteCallback, KeyboardCallback keyboardCallback, MouseCallback mouseCallback) : base(deviceGuid, devicePath, remoteCallback, keyboardCallback, mouseCallback) { if (devicePath.IndexOf(VidSMK, StringComparison.OrdinalIgnoreCase) != -1 || devicePath.IndexOf(VidTopseed, StringComparison.OrdinalIgnoreCase) != -1) { _deviceType = DeviceType.SmkTopseed; } else { _deviceType = DeviceType.Microsoft; } }
/// <summary> /// Unregister a specified KeyCodeEventPair and KeyboardCallback. /// </summary> private void UnregisterKeyEvent(KeyCodeEventPair keyCodeEvent, KeyboardCallback callback) { if (registeredCallbacks.ContainsKey(keyCodeEvent)) { List <KeyboardCallback> callbackList = registeredCallbacks[keyCodeEvent]; if (callbackList.Remove(callback)) { // remove the list from the dictionary if no callbacks are left if (callbackList.Count == 0) { registeredCallbacks.Remove(keyCodeEvent); } } } }
protected Driver(Guid deviceGuid, string devicePath, RemoteCallback remoteCallback, KeyboardCallback keyboardCallback, MouseCallback mouseCallback) { if (String.IsNullOrEmpty(devicePath)) { throw new ArgumentNullException("devicePath"); } _deviceGuid = deviceGuid; _devicePath = devicePath; _remoteCallback = remoteCallback; _keyboardCallback = keyboardCallback; _mouseCallback = mouseCallback; }
public static void clearCallbacks() { // Clear callbacks keyPressedCallback = null; keyReleasedCallback = null; padMovedCallback = null; buttonPressedCallback = null; buttonReleasedCallback = null; mouseMovedCallback = null; mousePressedCallback = null; mouseReleasedCallback = null; // Reset states oldMouse = newMouse; oldKeyboard = newKeyboard; oldGamePad = newGamePad; }
public Callback(KeyboardCallback function) { Function = function; LowLevelKeyboardProc = new LowLevelKeyboardProc(HookCallback); HookID = SetHook(LowLevelKeyboardProc); }
public KeyboardRegistration(KeyCodeEventPair keyCodeEvent, KeyboardCallback callback) { this.keyCodeEvent = keyCodeEvent; this.callback = callback; isRegistered = true; }
/// <summary> /// Prevents a default instance of the <see cref="Switchblade" /> class from being created. /// </summary> /// <remarks> /// The constructor will disable all OS gestures, to enable them, use the Touchpad property /// and call the EnableOSGesture() method to enable gestures wanted. /// </remarks> private Switchblade() { _log = LogManager.GetLogger(this); _log.Info("Switchblade is initializing"); _log.Debug("Calling RzSBStart()"); var result = NativeMethods.RzSBStart(); if (HRESULT.RZSB_FAILED(result)) { // Try one more time result = NativeMethods.RzSBStart(); if (HRESULT.RZSB_FAILED(result)) { throw new NativeCallException("RzSBStart", result); } } _log.Debug("Querying SDK for capabilities struct..."); Capabilities caps; result = NativeMethods.RzSBQueryCapabilities(out caps); if (HRESULT.RZSB_FAILED(result)) { throw new NativeCallException("RzSBQueryCapabilities", result); } Capabilities = caps; _log.InfoFormat( "SDK start successful! Working against SDK ver {0} ({1})", Capabilities.Version, Capabilities.BEVersion); _log.InfoFormat( "Number of surfaces: {0}, number of DKs: {1}", Capabilities.SurfaceCount, Capabilities.DynamicKeyCount); #if DEBUG _log.DebugFormat( System.Globalization.CultureInfo.InvariantCulture, "HW type: {0}, DK size: {1}x{2}, DK arr: X={3} Y={4}", Capabilities.HardwareType, Capabilities.DynamicKeySize.X, Capabilities.DynamicKeySize.Y, Capabilities.DynamicKeyArrangement.X, Capabilities.DynamicKeyArrangement.Y); for (var i = 0; i < Capabilities.SurfaceCount; i++) { var pf = Capabilities.Pixelformat[i]; var sg = Capabilities.Surfacegeometry[i]; _log.DebugFormat( System.Globalization.CultureInfo.InvariantCulture, "Surface #{0}: PixelFormat={1}, SurfaceGeometry: X={2}, Y={3}", i, pf, sg.X, sg.Y); } #endif _log.Debug("Creating new app event callback"); _appEventCallback = HandleAppEvent; _log.Debug("Calling RzSBAppEventSetCallback"); result = NativeMethods.RzSBAppEventSetCallback(_appEventCallback); if (HRESULT.RZSB_FAILED(result)) { throw new NativeCallException("RzSBAppEventSetCallback", result); } _log.Info("Setting up touchpad"); _touchpad = SharpBlade.Touchpad.Instance; Touchpad.DisableOSGesture(GestureTypes.All); _log.Info("Setting up keyboard"); // Keyboard capture callback _log.Debug("Creating keyboard callback"); _keyboardCallback = HandleKeyboardEvent; _log.Debug("Calling RzSBDynamicKeySetCallback"); result = NativeMethods.RzSBKeyboardCaptureSetCallback(_keyboardCallback); if (HRESULT.RZSB_FAILED(result)) { throw new NativeCallException("RzSBKeyboardCaptureSetCallback", result); } _log.Info("Setting up dynamic keys"); _dynamicKeys = SharpBlade.DynamicKeys.Instance; _log.Debug("Initializing the RzDisplayState file manager"); _displayStateFile = new DisplayStateFile(); }
public void SetKeyboardCallback(KeyboardCallback callback) { State.KeyboardFunction = callback; }
/// <summary> /// Sets the keyboard callback for the current window. /// </summary> /// <param name="func"> /// The new keyboard callback function. See <see cref="KeyboardCallback" />. /// </param> /// <remarks> /// <para> /// <b>glutKeyboardFunc</b> sets the keyboard callback for the current window. /// When a user types into the window, each key press generating an ASCII /// character will generate a keyboard callback. The <i>key</i> callback /// parameter is the generated ASCII character. The state of modifier keys such /// as Shift cannot be determined directly; their only effect will be on the /// returned ASCII data. The <i>x</i> and <i>y</i> callback parameters indicate /// the mouse location in window relative coordinates when the key was pressed. /// When a new window is created, no keyboard callback is initially registered, /// and ASCII key strokes in the window are ignored. Passing <c>null</c> to /// <b>glutKeyboardFunc</b> disables the generation of keyboard callbacks. /// </para> /// <para> /// During a keyboard callback, <see cref="glutGetModifiers" /> may be called to /// determine the state of modifier keys when the keystroke generating the /// callback occurred. /// </para> /// <para> /// Also, see <see cref="glutSpecialFunc" /> for a means to detect non-ASCII key /// strokes. /// </para> /// </remarks> /// <seealso cref="KeyboardCallback" /> /// <seealso cref="glutGetModifiers" /> /// <seealso cref="glutSpecialFunc" /> // GLUTAPI void APIENTRY glutKeyboardFunc(void (GLUTCALLBACK *func)(unsigned char key, int x, int y)); public static void glutKeyboardFunc([In] KeyboardCallback func) { keyboardCallback = func; __glutKeyboardFunc(keyboardCallback); }
private static void DetectMCE(int[] timingData, KeyboardCallback keyboardCallback, MouseCallback mouseCallback) { // Mouse: 0 0001 xxxxxxxxxxxxxxxxxxxxxxxxxxxxx // Keyboard: 0 0100 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx const int HalfBit_None = 0; const int HalfBit_Zero = 1; const int HalfBit_One = 2; for (int i = 0; i < timingData.Length; i++) { int duration = Math.Abs(timingData[i]); bool pulse = (timingData[i] > 0); #region Working data ... if (MCE_Data.State != MceKeyboardDetectState.Header) { switch (MCE_Data.HalfBit) { #region HalfBit_None case HalfBit_None: if (IsBetween(duration, 100, 450)) { MCE_Data.HalfBit = (pulse ? HalfBit_One : HalfBit_Zero); } else if (IsBetween(duration, 500, 800)) { //Trace.WriteLine("Bad bit sequence double {0}", pulse); MCE_Data.HalfBit = (pulse ? HalfBit_One : HalfBit_Zero); //MCE_Data = new MceDetectionData(); return; } else { // Over Length duration (Treat as a Zero bit) //Trace.WriteLine("Bad duration {0}", duration); MCE_Data.Working <<= 1; MCE_Data.Bit--; } break; #endregion HalfBit_None #region HalfBit_Zero case HalfBit_Zero: if (IsBetween(duration, 100, 450)) { if (pulse) { MCE_Data.Working <<= 1; MCE_Data.Bit--; MCE_Data.HalfBit = HalfBit_None; } else { //Trace.WriteLine("Bad bit sequence 00"); MCE_Data = new MceDetectionData(); //return; } } else if (IsBetween(duration, 500, 800)) { if (pulse) { MCE_Data.Working <<= 1; MCE_Data.Bit--; MCE_Data.HalfBit = HalfBit_One; } else { //Trace.WriteLine("Bad bit sequence 00 0"); MCE_Data = new MceDetectionData(); //return; } } else { //Trace.WriteLine("Bad duration {0}", duration); if (MCE_Data.Bit == 1) { MCE_Data.Working <<= 1; //MceKeyboard_Data.Working |= 1; MCE_Data.Bit--; MCE_Data.HalfBit = HalfBit_None; //i--; } else { MCE_Data = new MceDetectionData(); } //return; } break; #endregion HalfBit_Zero #region HalfBit_One case HalfBit_One: if (IsBetween(duration, 100, 450)) { if (!pulse) { MCE_Data.Working <<= 1; MCE_Data.Working |= 1; MCE_Data.Bit--; MCE_Data.HalfBit = HalfBit_None; } else { //Trace.WriteLine("Bad bit sequence 11"); MCE_Data = new MceDetectionData(); //return; } } else if (IsBetween(duration, 500, 800)) { if (!pulse) { MCE_Data.Working <<= 1; MCE_Data.Working |= 1; MCE_Data.Bit--; MCE_Data.HalfBit = HalfBit_Zero; } else { //Trace.WriteLine("Bad bit sequence 11 1"); MCE_Data = new MceDetectionData(); //return; } } else { //Trace.WriteLine("Bad duration {0}", duration); if (MCE_Data.Bit == 1) { MCE_Data.Working <<= 1; MCE_Data.Working |= 1; MCE_Data.Bit--; MCE_Data.HalfBit = HalfBit_None; //i--; } else { MCE_Data = new MceDetectionData(); //return; } } break; #endregion HalfBit_One } } #endregion Working data ... switch (MCE_Data.State) { #region Header case MceKeyboardDetectState.Header: if (pulse && IsBetween(duration, 2600, 3300)) { MCE_Data.State = MceKeyboardDetectState.CodeType; MCE_Data.Type = 0; MCE_Data.Bit = 5; MCE_Data.Working = 0; } break; #endregion Header #region CodeType case MceKeyboardDetectState.CodeType: if (MCE_Data.Bit == 0) { MCE_Data.Type = MCE_Data.Working; if (MCE_Data.Type == MceKeyboard) { MCE_Data.State = MceKeyboardDetectState.KeyboardIgnore; MCE_Data.Bit = 16; MCE_Data.Working = 0; } else if (MCE_Data.Type == MceMouse) { MCE_Data.State = MceKeyboardDetectState.MouseIgnore; MCE_Data.Bit = 8; MCE_Data.Working = 0; } else { //Trace.WriteLine("KB: Invalid Type {0}", MceKeyboard_Data.Type); return; } } break; #endregion CodeType #region Keyboard #region KeyboardIgnore case MceKeyboardDetectState.KeyboardIgnore: if (MCE_Data.Bit == 0) { MCE_Data.State = MceKeyboardDetectState.KeyCode; MCE_Data.Bit = 8; MCE_Data.Working = 0; } break; #endregion KeyboardIgnore #region KeyCode case MceKeyboardDetectState.KeyCode: if (MCE_Data.Bit == 0) { MCE_Data.KeyCode = MCE_Data.Working; MCE_Data.State = MceKeyboardDetectState.Modifiers; MCE_Data.Bit = 8; MCE_Data.Working = 0; } break; #endregion KeyCode #region Modifiers case MceKeyboardDetectState.Modifiers: if (MCE_Data.Bit == 0) { MCE_Data.Modifiers = MCE_Data.Working; keyboardCallback(MCE_Data.KeyCode, MCE_Data.Modifiers); MCE_Data = new MceDetectionData(); } break; #endregion Modifiers #endregion Keyboard #region Mouse #region MouseIgnore case MceKeyboardDetectState.MouseIgnore: if (MCE_Data.Bit == 0) { MCE_Data.State = MceKeyboardDetectState.DeltaY; MCE_Data.Bit = 7; MCE_Data.Working = 0; } break; #endregion MouseIgnore #region DeltaY case MceKeyboardDetectState.DeltaY: if (MCE_Data.Bit == 0) { MCE_Data.DeltaY = ScaleMouseDelta((int) MCE_Data.Working); MCE_Data.State = MceKeyboardDetectState.DeltaX; MCE_Data.Bit = 7; MCE_Data.Working = 0; } break; #endregion DeltaY #region DeltaX case MceKeyboardDetectState.DeltaX: if (MCE_Data.Bit == 0) { MCE_Data.DeltaX = ScaleMouseDelta((int) MCE_Data.Working); MCE_Data.State = MceKeyboardDetectState.Right; MCE_Data.Bit = 1; MCE_Data.Working = 0; } break; #endregion DeltaX #region Right case MceKeyboardDetectState.Right: if (MCE_Data.Bit == 0) { MCE_Data.Right = (MCE_Data.Working == 1); MCE_Data.State = MceKeyboardDetectState.Left; MCE_Data.Bit = 1; MCE_Data.Working = 0; } break; #endregion Right #region Left case MceKeyboardDetectState.Left: if (MCE_Data.Bit == 0) { MCE_Data.Left = (MCE_Data.Working == 1); MCE_Data.State = MceKeyboardDetectState.Checksum; MCE_Data.Bit = 5; MCE_Data.Working = 0; } break; #endregion Left #region Checksum case MceKeyboardDetectState.Checksum: if (MCE_Data.Bit == 0) { mouseCallback(MCE_Data.DeltaX, MCE_Data.DeltaY, MCE_Data.Right, MCE_Data.Left); MCE_Data = new MceDetectionData(); } break; #endregion Checksum #endregion Mouse } if (MCE_Data.Bit < 0) MCE_Data = new MceDetectionData(); } }
private void FireKeyboardCallback(int id, KeyboardCallback data) { ThreadPool.QueueUserWorkItem(threadProc => _keyboardCallback(data.Id, data.Code, data.State, data.Info)); }
public static void setKeyReleasedCallback(KeyboardCallback callback) { keyReleasedCallback = callback; }
public static void setKeyPressedCallback(KeyboardCallback callback) { keyPressedCallback = callback; }
static extern void GLUT_RegisterKeyboard( KeyboardCallback keyDownCallback, KeyboardCallback keyUpCallback);
private static extern void glutKeyboardFunc(KeyboardCallback func);
private static extern void __glutKeyboardFunc(KeyboardCallback func);
protected Driver(Guid deviceGuid, string devicePath, RemoteCallback remoteCallback, KeyboardCallback keyboardCallback, MouseCallback mouseCallback) { if (String.IsNullOrEmpty(devicePath)) throw new ArgumentNullException("devicePath"); _deviceGuid = deviceGuid; _devicePath = devicePath; _remoteCallback = remoteCallback; _keyboardCallback = keyboardCallback; _mouseCallback = mouseCallback; }
internal static extern HRESULT RzSBKeyboardCaptureSetCallback([In] KeyboardCallback callback);
/// <summary> /// Decode timing data to discover IR Protocol and packet payload. /// </summary> /// <param name="timingData">Input timing data.</param> /// <param name="remoteCallback">Method to call when Remote button decoded.</param> /// <param name="keyboardCallback">Method to call when Keyboard event decoded.</param> /// <param name="mouseCallback">Method to call when Mouse event decoded.</param> public static void DecodeIR(int[] timingData, RemoteCallback remoteCallback, KeyboardCallback keyboardCallback, MouseCallback mouseCallback) { if (timingData == null) return; try { DetectDaewoo(timingData, remoteCallback); //DetectITT(timingData, remoteCallback); DetectJVC(timingData, remoteCallback); DetectMatsushita(timingData, remoteCallback); DetectMitsubishi(timingData, remoteCallback); DetectNEC(timingData, remoteCallback); DetectNRC17(timingData, remoteCallback); DetectPanasonic(timingData, remoteCallback); DetectRC5(timingData, remoteCallback); DetectRC6(timingData, remoteCallback); DetectRCA(timingData, remoteCallback); //DetectRCMM(timingData, remoteCallback); DetectRECS80(timingData, remoteCallback); //DetectSharp(timingData, remoteCallback); DetectSIRC(timingData, remoteCallback); DetectToshiba(timingData, remoteCallback); //DetectXSAT(timingData, remoteCallback); DetectMCE(timingData, keyboardCallback, mouseCallback); //DetectIMon(timingData, keyboardCallback, mouseCallback); } #if TRACE catch (Exception ex) { Trace.WriteLine(ex.ToString()); #else catch { #endif Daewoo_Data = new RemoteDetectionData(); JVC_Data = new RemoteDetectionData(); Matsushita_Data = new RemoteDetectionData(); Mitsubishi_Data = new RemoteDetectionData(); NEC_Data = new RemoteDetectionData(); NRC17_Data = new RemoteDetectionData(); Panasonic_Data = new RemoteDetectionData(); RC5_Data = new RemoteDetectionData(); RC6_Data = new RemoteDetectionData(); RCA_Data = new RemoteDetectionData(); RECS80_Data = new RemoteDetectionData(); SIRC_Data = new RemoteDetectionData(); Toshiba_Data = new RemoteDetectionData(); MCE_Data = new MceDetectionData(); } }
public void LaunchPlayStore() { KeyboardCallback cb = new KeyboardCallback(); keyboardFragment.Call("launchPlayStore", cb); }
public DriverVista(Guid deviceGuid, string devicePath, RemoteCallback remoteCallback, KeyboardCallback keyboardCallback, MouseCallback mouseCallback) : base(deviceGuid, devicePath, remoteCallback, keyboardCallback, mouseCallback) { }
private void OnKeyboardCallback(LowLevelKeyboardHookCallbackEventArgs e) { KeyboardCallback?.Invoke(this, e); }
public static void GlutKeyboardFunc([In] KeyboardCallback func) { _keyboardCallback = func; glutKeyboardFunc(_keyboardCallback); }
public DriverReplacement(Guid deviceGuid, string devicePath, RemoteCallback remoteCallback, KeyboardCallback keyboardCallback, MouseCallback mouseCallback) : base(deviceGuid, devicePath, remoteCallback, keyboardCallback, mouseCallback) { if (devicePath.IndexOf(VidSMK, StringComparison.OrdinalIgnoreCase) != -1 || devicePath.IndexOf(VidTopseed, StringComparison.OrdinalIgnoreCase) != -1) _deviceType = DeviceType.SmkTopseed; else _deviceType = DeviceType.Microsoft; }