/// <summary> /// Let everybody know that this HID message may not be handled by anyone else /// </summary> /// <param name="msg">System.Windows.Forms.Message</param> /// <returns>Command handled</returns> public bool WndProc(Message msg) { if (controlEnabled && (msg.Msg == Win32.Const.WM_APPCOMMAND)) { int command = Win32.Macro.GET_APPCOMMAND_LPARAM(msg.LParam); InputDevices.LastHidRequest = (AppCommands)command; RemoteButton button = RemoteButton.None; if ((AppCommands)command == AppCommands.VolumeUp) { button = RemoteButton.VolumeUp; } if ((AppCommands)command == AppCommands.VolumeDown) { button = RemoteButton.VolumeDown; } if ((AppCommands)command == AppCommands.MediaChannelUp) { button = RemoteButton.ChannelUp; } if ((AppCommands)command == AppCommands.MediaChannelDown) { button = RemoteButton.ChannelDown; } if (button != RemoteButton.None) { // Get & execute Mapping if (_inputHandler.MapAction((int)button)) { if (logVerbose) { Log.Info("MCE: Command \"{0}\" mapped", button); } } else if (logVerbose) { Log.Info("MCE: Command \"{0}\" not mapped", button); } } return(true); } return(false); }
/// <summary> /// Let everybody know that this HID message may not be handled by anyone else /// </summary> /// <param name="msg">System.Windows.Forms.Message</param> /// <returns>Command handled</returns> public bool WndProc(Message msg) { if (controlEnabled && (msg.Msg == 0x0319)) { int command = (msg.LParam.ToInt32() >> 16) & ~0xF000; InputDevices.LastHidRequest = (AppCommands)command; RemoteButton button = RemoteButton.None; if ((AppCommands)command == AppCommands.VolumeUp) { button = RemoteButton.VolumeUp; } if ((AppCommands)command == AppCommands.VolumeDown) { button = RemoteButton.VolumeDown; } if ((AppCommands)command == AppCommands.MediaChannelUp) { button = RemoteButton.ChannelUp; } if ((AppCommands)command == AppCommands.MediaChannelDown) { button = RemoteButton.ChannelDown; } if (button != RemoteButton.None) { // Get & execute Mapping if (_inputHandler.MapAction((int)button)) { if (logVerbose) { Log.Info("MCE: Command \"{0}\" mapped", button); } } else if (logVerbose) { Log.Info("MCE: Command \"{0}\" not mapped", button); } } return(true); } return(false); }
public void X10Command(string bszCommand, EX10Command eCommand, int lAddress, EX10Key EKeyState, int lSequence, EX10Comm eCommandType, object varTimestamp) { if ((EKeyState == EX10Key.X10KEY_ON || EKeyState == EX10Key.X10KEY_REPEAT) && lSequence != 2) { if (_x10UseChannelControl && (lAddress != ((_x10Channel - 1) * 16))) { return; } int keypress = (int)Enum.Parse(typeof(EX10Command), eCommand.ToString()); if (X10KeyPressed != null) { X10KeyPressed(keypress); } if (_inputHandler != null) { _inputHandler.MapAction(keypress); } if (_logVerbose) { Log.Info("X10Remote: Command Start --------------------------------------------"); Log.Info("X10Remote: bszCommand = {0}", bszCommand.ToString()); Log.Info("X10Remote: eCommand = {0} - {1}", keypress, eCommand.ToString()); Log.Info("X10Remote: eCommandType = {0}", eCommandType.ToString()); Log.Info("X10Remote: eKeyState = {0}", EKeyState.ToString()); Log.Info("X10Remote: lAddress = {0}", lAddress.ToString()); Log.Info("X10Remote: lSequence = {0}", lSequence.ToString()); Log.Info("X10Remote: varTimestamp = {0}", varTimestamp.ToString()); Log.Info("X10Remote: Command End ----------------------------------------------"); } } }
public bool WndProc(ref Message msg, out Action action, out char key, out Keys keyCode) { action = null; key = (char)0; keyCode = Keys.A; if (controlEnabled) { // we are only interested in WM_APPCOMMAND if (msg.Msg != 0x0319) { return(false); } AppCommands appCommand = (AppCommands)((msg.LParam.ToInt32() >> 16) & ~0xF000); // find out which request the MCE remote handled last if ((appCommand == InputDevices.LastHidRequest) && (appCommand != AppCommands.VolumeDown) && (appCommand != AppCommands.VolumeUp)) { if (Enum.IsDefined(typeof(AppCommands), InputDevices.LastHidRequest)) { // possible that it is the same request mapped to an app command? if (Environment.TickCount - InputDevices.LastHidRequestTick < 500) { return(true); } } } InputDevices.LastHidRequest = appCommand; if (logVerbose) { Log.Info("HID: Command: {0} - {1}", ((msg.LParam.ToInt32() >> 16) & ~0xF000), InputDevices.LastHidRequest.ToString()); } if (!_inputHandler.MapAction((msg.LParam.ToInt32() >> 16) & ~0xF000)) { return(false); } msg.Result = new IntPtr(1); return(true); } return(false); }
public bool WndProc(ref Message msg, out Action action, out char key, out Keys keyCode) { keyCode = Keys.A; key = (char)0; action = null; switch ((FireDTVConstants.FireDTVWindowMessages)msg.Msg) { case FireDTVConstants.FireDTVWindowMessages.DeviceAttached: Log.Info("FireDTVRemote: DeviceAttached"); StartFireDTVComms(); break; case FireDTVConstants.FireDTVWindowMessages.DeviceDetached: Log.Info("FireDTVRemote: DeviceDetached"); _fireDTV.SourceFilters.RemoveByHandle((uint)msg.WParam); break; case FireDTVConstants.FireDTVWindowMessages.DeviceChanged: Log.Info("FireDTVRemote: DeviceChanged"); StartFireDTVComms(); break; case FireDTVConstants.FireDTVWindowMessages.RemoteControlEvent: if (_enabled) { int remoteKeyCode = msg.LParam.ToInt32(); if (_logVerbose) { Log.Info("FireDTVRemote: RemoteControlEvent {0}", remoteKeyCode); } if (!_inputHandler.MapAction(remoteKeyCode)) { return(false); } msg.Result = new IntPtr(1); return(true); } break; } return(false); }
/// <summary> /// /// </summary> /// <param name="msg"></param> /// <param name="action"></param> /// <param name="key"></param> /// <param name="keyCode"></param> /// <returns></returns> public bool WndProcAppCommand(ref Message msg, out Mapping mappedCommand, bool shouldRaiseAction = true) { mappedCommand = null; AppCommands appCommand = (AppCommands)Win32.Macro.GET_APPCOMMAND_LPARAM(msg.LParam); // find out which request the MCE remote handled last if ((appCommand == InputDevices.LastHidRequest) && (appCommand != AppCommands.VolumeDown) && (appCommand != AppCommands.VolumeUp)) { if (Enum.IsDefined(typeof(AppCommands), InputDevices.LastHidRequest)) { // possible that it is the same request mapped to an app command? if (Environment.TickCount - InputDevices.LastHidRequestTick < 500) { return(true); } } } InputDevices.LastHidRequest = appCommand; if (logVerbose) { Log.Info("AppCommand: {0} - {1}", appCommand, InputDevices.LastHidRequest.ToString()); } mappedCommand = _inputHandler.GetMapping(((int)appCommand).ToString()); if (shouldRaiseAction) { if (!_inputHandler.MapAction((int)appCommand)) { return(false); } } msg.Result = new IntPtr(1); return(true); }
/// <summary> /// Let everybody know that this HID message may not be handled by anyone else /// </summary> /// <param name="msg">System.Windows.Forms.Message</param> /// <returns>Command handled</returns> public bool WndProc(ref Message msg) { if (_remoteActive) { if (msg.Msg == WM_KEYDOWN || msg.Msg == WM_SYSKEYDOWN || msg.Msg == WM_APPCOMMAND || msg.Msg == WM_LBUTTONDOWN || msg.Msg == WM_RBUTTONDOWN || msg.Msg == WM_MOUSEMOVE) { switch ((Keys)msg.WParam) { case Keys.ControlKey: break; case Keys.ShiftKey: break; case Keys.Menu: break; default: int keycode = (int)msg.WParam; AppCommands appCommand = (AppCommands)((msg.LParam.ToInt32() >> 16) & ~0xF000); // find out which request the MCE remote handled last if ((appCommand == InputDevices.LastHidRequest) && (appCommand != AppCommands.VolumeDown) && (appCommand != AppCommands.VolumeUp)) { if (Enum.IsDefined(typeof(AppCommands), InputDevices.LastHidRequest)) { // possible that it is the same request mapped to an app command? if (Environment.TickCount - InputDevices.LastHidRequestTick < 500) { return(true); } } } InputDevices.LastHidRequest = appCommand; // Due to the non-perfect placement of the OK button we allow the user to remap the joystick to okay. if (_mapMouseButton) { if (msg.Msg == WM_LBUTTONDOWN) { if (_verboseLogging) { Log.Debug("Centarea: Command \"{0}\" mapped for left mouse button", keycode); } keycode = 13; } if (msg.Msg == WM_RBUTTONDOWN) { if (_verboseLogging) { Log.Debug("Centarea: Command \"{0}\" mapped for right mouse button", keycode); } keycode = 10069; } } // Since mouse support is semi optimal we have this option to use the joystick like cursor keys if (_mapJoystick && GUIGraphicsContext.Fullscreen) { if (msg.Msg == WM_MOUSEMOVE) { Point p = new Point(msg.LParam.ToInt32()); _ignoreDupMsg++; // since our ResetCursor() triggers a mouse move MSG as well we ignore every second event if (_ignoreDupMsg % 2 == 0) { GUIGraphicsContext.ResetCursor(false); } // we ignore double actions for the configured time if (Environment.TickCount - _lastMouseTick < 400) { return(false); } MouseDirection mmove = OnMouseMoved(p); _lastMouseTick = Environment.TickCount; _ignoreDupMsg = 0; switch (mmove) { case MouseDirection.Up: keycode = 38; break; case MouseDirection.Right: keycode = 39; break; case MouseDirection.Down: keycode = 40; break; case MouseDirection.Left: keycode = 37; break; } if (mmove != MouseDirection.None) { GUIGraphicsContext.ResetCursor(false); if (_verboseLogging) { Log.Debug("Centarea: Command \"{0}\" mapped for mouse movement", mmove.ToString()); } } } } // The Centarea Remote sends key combos. Therefore we use this trick to get a 1:1 mapping if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) { keycode += 1000; } if ((Control.ModifierKeys & Keys.Control) == Keys.Control) { keycode += 10000; } if ((Control.ModifierKeys & Keys.Alt) == Keys.Alt) { keycode += 100000; } try { // Get & execute Mapping if (_inputHandler.MapAction(keycode)) { if (_verboseLogging) { Log.Debug("Centarea: Command \"{0}\" mapped", keycode); } } else { if (keycode > 0) { Log.Debug("Centarea: Command \"{0}\" not mapped", keycode); } return(false); } } catch (ApplicationException) { return(false); } msg.Result = new IntPtr(1); break; } return(true); } } return(false); }
private void OnReceive(string strReceive) { if (_logVerbose) { Log.Info("HCW: received: {0}", strReceive); } string msg = strReceive.Split('~')[0]; if (_logVerbose) { Log.Info("HCW: Accepted: {0}", msg); } switch (msg.Split('|')[0]) { case "CMD": { // Time of button press - Use this for repeat delay calculations DateTime sentTime = DateTime.FromBinary(Convert.ToInt64(msg.Split('|')[2])); int newCommand = Convert.ToInt16(msg.Split('|')[1]); if (_logVerbose) { Log.Info("HCW: elapsed time: {0}", ((TimeSpan)(sentTime - _lastTime)).Milliseconds); } if (_logVerbose) { Log.Info("HCW: sameCommandCount: {0}", _sameCommandCount.ToString()); } if (_lastCommand == newCommand) { // button release time elapsed since last identical command // if so, reset counter & start new session if ((sentTime - _lastTime) > _buttonRelease) { _sameCommandCount = 0; // new session with this button if (_logVerbose) { Log.Info("HCW: same command, timeout true"); } } else { if (_logVerbose) { Log.Info("HCW: same command, timeout false"); } _sameCommandCount++; // button release time not elapsed } } else { _sameCommandCount = 0; // we got a new button } bool executeKey = false; // new button / session if (_sameCommandCount == 0) { executeKey = true; //here } //// we got the identical button often enough to accept it if (_sameCommandCount == _repeatFilter) { executeKey = true; } // we got the identical button accepted and still pressed, repeat with repeatSpeed if ((_sameCommandCount > _repeatFilter) && (_sameCommandCount > _lastExecutedCommandCount + _repeatSpeed)) { executeKey = true; } if (HCWKeyPressed != null) { _filterDoubleKlicks = true; } // double click filter if (executeKey && _filterDoubleKlicks) { int keyCode = newCommand; // strip remote type if (keyCode > 2000) { keyCode = keyCode - 2000; } else if (keyCode > 1000) { keyCode = keyCode - 1000; } if ((_sameCommandCount > 0) && (keyCode == 46 || //46 = fullscreen/green button keyCode == 37 || //37 = OK button keyCode == 56 || //56 = yellow button keyCode == 11 || //11 = red button keyCode == 41 || //41 = blue button keyCode == 13 || //13 = menu button keyCode == 15 || //15 = mute button keyCode == 48)) //48 = pause button { executeKey = false; if (_logVerbose) { Log.Info("HCW: doubleclick supressed: {0}", newCommand.ToString()); } } else { //Send command for remote control learning if (HCWKeyPressed != null) { HCWKeyPressed(newCommand); } } } if (executeKey) { _lastExecutedCommandCount = _sameCommandCount; _lastCommand = newCommand; //Send command to application... if (_inputHandler != null) { if (!_inputHandler.MapAction(newCommand)) { Log.Info("HCW: No mapping found"); } else { if (_logVerbose) { Log.Info("HCW: repeat filter accepted: {0}", newCommand.ToString()); } } } } _lastTime = sentTime; } break; case "APP": if (msg.Split('|')[1] == "STOP") { if (_logVerbose) { Log.Info("HCW: received STOP from HcwHelper"); } _controlEnabled = false; _exit = true; StopHcw(); } break; } }
/// <summary> /// Method is called, whenever a IR Comand is received via the IRTrans Server connection. /// </summary> /// <param name="asyn"></param> private void OnDataReceived(IAsyncResult asyn) { try { CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState; //Do an end receive first int bytesReceived = 0; bytesReceived = theSockId.thisSocket.EndReceive(asyn); // Map the received data to the structure IntPtr ptrReceive = Marshal.AllocHGlobal(bytesReceived); Marshal.Copy(theSockId.receiveBuffer, 0, ptrReceive, bytesReceived); NETWORKRECV netrecv = (NETWORKRECV)Marshal.PtrToStructure(ptrReceive, typeof(NETWORKRECV)); if (logVerbose) { Log.Info("IRTrans: Command Start --------------------------------------------"); Log.Info("IRTrans: Client = {0}", netrecv.clientid); Log.Info("IRTrans: Status = {0}", (IrTransStatus)netrecv.statustype); Log.Info("IRTrans: Remote = {0}", netrecv.remote); Log.Info("IRTrans: Command Num. = {0}", netrecv.command_num.ToString()); Log.Info("IRTrans: Command = {0}", netrecv.command); Log.Info("IRTrans: Data = {0}", netrecv.data); Log.Info("IRTrans: Command End ----------------------------------------------"); } // Do an action only on Receive and if the command came from the selected Remote if ((IrTransStatus)netrecv.statustype == IrTransStatus.STATUS_RECEIVE) { if (netrecv.remote.Trim() == remoteModel) { try { if (irtransHandler.MapAction(netrecv.command.Trim())) { if (logVerbose) { Log.Info("IRTrans: Action mapped"); } } else { if (logVerbose) { Log.Info("IRTrans: Action not mapped"); } } } catch (Exception ex) { if (logVerbose) { Log.Info("IRTrans: Exception in IRTranshandler: {0}", ex.Message); } } } } Marshal.FreeHGlobal(ptrReceive); WaitForData(); } catch (ObjectDisposedException) {} catch (SocketException se) { if (logVerbose) { Log.Info("IRTrans: Error on receive from socket: {0}", se.Message); } } }
private void SendActions(JoystickState state) { int actionCode = -1; int actionParam = -1; int curAxisValue = 0; // todo: timer stuff!! // buttons first! byte[] buttons = state.GetButtons(); int button = 0; string pressedButtons = ""; // button combos string sep = ""; foreach (byte b in buttons) { if (0 != (b & 0x80)) { pressedButtons += sep + button.ToString("00"); sep = ","; } button++; } if ((ButtonComboKill != "") && (ButtonComboKill == pressedButtons)) { if (null != _lastProc) { actionCode = (int)joyButton.comboKillProcess; actionParam = _lastProc.Id; } } else if ((ButtonComboClose != "") && (ButtonComboClose == pressedButtons)) { if (null != _lastProc) { actionCode = (int)joyButton.comboCloseProcess; actionParam = _lastProc.Id; } } // single buttons if (actionCode == -1) { button = 0; bool foundButton = false; foreach (byte b in buttons) { if (0 != (b & 0x80)) { foundButton = true; break; } button++; } if (foundButton) { if ((button >= 0) && (button <= 19)) { // don't need no stinkin' enum-constants here.... actionCode = 3030 + button; } } } // pov next if (actionCode == -1) { int[] pov = state.GetPointOfView(); switch (pov[0]) { case 0: { actionCode = (int)joyButton.povN; break; } case 9000: { actionCode = (int)joyButton.povE; break; } case 18000: { actionCode = (int)joyButton.povS; break; } case 27000: { actionCode = (int)joyButton.povW; break; } } } if (actionCode == -1) { // axes next if (Math.Abs(state.X) > _axisLimit) { curAxisValue = state.X; if (state.X > 0) { actionCode = (int)joyButton.axisXUp; // right } else { actionCode = (int)joyButton.axisXDown; // left } } else if (Math.Abs(state.Y) > _axisLimit) { curAxisValue = state.Y; if (state.Y > 0) { // down actionCode = (int)joyButton.axisYUp; } else { // up actionCode = (int)joyButton.axisYDown; } } else if (Math.Abs(state.Z) > _axisLimit) { curAxisValue = state.Z; if (state.Z > 0) { actionCode = (int)joyButton.axisZUp; } else { actionCode = (int)joyButton.axisZDown; } } } if (actionCode == -1) { // rotation if (Math.Abs(state.Rx) > _axisLimit) { curAxisValue = state.Rx; if (state.Rx > 0) { actionCode = (int)joyButton.rotationXUp; } else { actionCode = (int)joyButton.rotationXDown; } } else if (Math.Abs(state.Ry) > _axisLimit) { curAxisValue = state.Ry; if (state.Ry > 0) { actionCode = (int)joyButton.rotationYUp; } else { actionCode = (int)joyButton.rotationYDown; } } else if (Math.Abs(state.Rz) > _axisLimit) { curAxisValue = state.Rz; if (state.Rz > 0) { actionCode = (int)joyButton.rotationZUp; } else { actionCode = (int)joyButton.rotationZDown; } } } if (VerifyAction(actionCode, curAxisValue)) { Log.Info("mapping action {0}", actionCode); _inputHandler.MapAction(actionCode, actionParam); } }
/// <summary> /// Map a WndProc message and optionally execute it /// </summary> /// <param name="msg"></param> /// <returns></returns> private Mapping MapWndProcMessage(Message msg, bool shouldRaiseAction = true) { Mapping result = null; if (msg.Msg == WM_KEYDOWN || msg.Msg == WM_SYSKEYDOWN || msg.Msg == Win32.Const.WM_APPCOMMAND || msg.Msg == WM_LBUTTONDOWN || msg.Msg == WM_RBUTTONDOWN || msg.Msg == WM_MOUSEMOVE) { switch ((Keys)msg.WParam) { case Keys.ControlKey: break; case Keys.ShiftKey: break; case Keys.Menu: break; default: int keycode = (int)msg.WParam; AppCommands appCommand = (AppCommands)Win32.Macro.GET_APPCOMMAND_LPARAM(msg.LParam); InputDevices.LastHidRequest = appCommand; // Due to the non-perfect placement of the OK button we allow the user to remap the joystick to okay. if (_mapMouseButton) { if (msg.Msg == WM_LBUTTONDOWN) { if (_verboseLogging) { Log.Debug("Centarea: Command \"{0}\" mapped for left mouse button", keycode); } keycode = 13; } if (msg.Msg == WM_RBUTTONDOWN) { if (_verboseLogging) { Log.Debug("Centarea: Command \"{0}\" mapped for right mouse button", keycode); } keycode = 10069; } } // Since mouse support is semi optimal we have this option to use the joystick like cursor keys if (_mapJoystick && GUIGraphicsContext.Fullscreen) { if (msg.Msg == WM_MOUSEMOVE) { Point p = new Point(msg.LParam.ToInt32()); _ignoreDupMsg++; // since our ResetCursor() triggers a mouse move MSG as well we ignore every second event if (_ignoreDupMsg % 2 == 0) { GUIGraphicsContext.ResetCursor(false); } // we ignore double actions for the configured time if (Environment.TickCount - _lastMouseTick < 400) { return(null); } MouseDirection mmove = OnMouseMoved(p); _lastMouseTick = Environment.TickCount; _ignoreDupMsg = 0; switch (mmove) { case MouseDirection.Up: keycode = 38; break; case MouseDirection.Right: keycode = 39; break; case MouseDirection.Down: keycode = 40; break; case MouseDirection.Left: keycode = 37; break; } if (mmove != MouseDirection.None) { GUIGraphicsContext.ResetCursor(false); if (_verboseLogging) { Log.Debug("Centarea: Command \"{0}\" mapped for mouse movement", mmove.ToString()); } } } } // The Centarea Remote sends key combos. Therefore we use this trick to get a 1:1 mapping if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) { keycode += 1000; } if ((Control.ModifierKeys & Keys.Control) == Keys.Control) { keycode += 10000; } if ((Control.ModifierKeys & Keys.Alt) == Keys.Alt) { keycode += 100000; } try { result = _inputHandler.GetMapping(keycode.ToString()); if (shouldRaiseAction) { // Get & execute Mapping if (_inputHandler.MapAction(keycode)) { if (_verboseLogging) { Log.Debug("Centarea: Command \"{0}\" mapped", keycode); } } else { if (keycode > 0) { Log.Debug("Centarea: Command \"{0}\" not mapped", keycode); } return(null); } } } catch (ApplicationException ex) { Log.Error("CentAreaRemote:MapWndProcMessage: {0}", ex.Message); return(null); } msg.Result = new IntPtr(1); break; } } return(result); }
public void MapCommand() { string xmlFile = "TestDefault"; int newCommand = 0; InputHandler inputHandler = new InputHandler(xmlFile); inputHandler.MapAction(newCommand); }