private static void HandleMessage(object sender, WindowMessageEventArgs e) { // Handle WM_INPUT if (e.Message != 0x00FF) { return; } try { var data = RawInputData.FromHandle(e.LParam); // Game already registers and uses Mouse, so pass that back. if (data.Device.UsageAndPage == HidUsageAndPage.Mouse) { return; } // Mark the message as handled and return 0 for consumed. e.Result = IntPtr.Zero; ProcessInput(data); } catch (Exception ex) { Logging.Log($"Failed to process window message: {ex.Message}\n{ex.StackTrace}"); } }
private void OnReceiveRawInput(RawInputEventData data) { if (RawInputData.FromHandle(data.LParam) is RawInputKeyboardData keyboardData) { ReceiveRawInputKeyboardData?.Invoke(keyboardData); } }
public static byte[] GenerateByteArray(RawInputData rawInputData) { dynamic dataObject = rawInputData; EDeviceType deviceType = RawInputWrapper.GetCustomDeviceType(rawInputData.Device); EEventType eventType; byte[] ByteData = new byte[] { }; switch (deviceType) { case EDeviceType.Keyboard: eventType = (dataObject.Keyboard.Flags.ToString() == "Down") ? EEventType.KeyPressed : EEventType.KeyReleased; int keyCode = (dataObject.Keyboard.VirutalKey); int scanCode = (dataObject.Keyboard.ScanCode); ByteData = ByteData.Combine(BitConverter.GetBytes((int)deviceType)); ByteData = ByteData.Combine(BitConverter.GetBytes((int)eventType)); ByteData = ByteData.Combine(BitConverter.GetBytes((int)keyCode)); ByteData = ByteData.Combine(BitConverter.GetBytes((int)scanCode)); break; case EDeviceType.Joystick: int size = dataObject.Hid.ElementSize; byte[] content = dataObject.Hid.RawData; ByteData = ByteData.Combine(BitConverter.GetBytes((int)deviceType)); ByteData = ByteData.Combine(BitConverter.GetBytes((int)size)); ByteData = ByteData.Combine(content); break; } return(ByteData.ToArray()); }
private IntPtr WndProcHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { const int WM_INPUT = 0x00FF; if (msg == WM_INPUT) { var data = RawInputData.FromHandle(lParam); switch (data) { case RawInputMouseData mouse: if (mouse.Mouse.Buttons != RawMouseButtonFlags.None && !mouse.Mouse.Buttons.ToString().Contains("Up")) { var button = GetButtonFromFlags(mouse.Mouse.Buttons); if (button != RawMouseButton.None) { SetTextBoxText(String.Format("{0} {1}", GetFancyDeviceName(mouse.Device), button), data); } } break; case RawInputKeyboardData keyboard: SetTextBoxText(String.Format("{0} {1}", GetFancyDeviceName(keyboard.Device), (Keys)keyboard.Keyboard.VirutalKey), data); break; } } return(IntPtr.Zero); }
private void OnReceiveRawInput(RawInputEventData data) { if (RawInputData.FromHandle(data.LParam) is RawInputMouseData mouseData) { ReceiveRawInputMouseData?.Invoke(mouseData); } }
private void OnReceiveRawInput(IntPtr lParam) { if (RawInputData.FromHandle(lParam) is RawInputMouseData data && data.Mouse.Flags.HasFlag(RawMouseFlags.MoveRelative)) { AddDif(data.Mouse.LastX, data.Mouse.LastY); } }
private void OnReceiveRawInput(IntPtr lParam) { var data = RawInputData.FromHandle(lParam); if (data is RawInputMouseData mouseData && mouseData.Mouse.Flags.HasFlag(RawMouseFlags.MoveRelative)) { AddDif(mouseData.Mouse.LastX, mouseData.Mouse.LastY); }
private void OnReceiveRawInput(RawInputEventData data) { var buf = RawInputData.GetBufferedData(); for (int i = 0; i < buf.Length; i++) { logToUi.AddLog($"Buffer[{i}]: Type = {buf[i].Header.Type}"); } }
private void OnControllerInput(RawInputData data) { if (isStarted == true && hidDropdown.SelectedIndex >= 0 && Program.Hids.ConnectedHids[hidDropdown.SelectedIndex] != null && data.Header.Type == RawInputDeviceType.Hid) { RawInputHidData hid = (RawInputHidData)data; Program.Gamepad.Update(hid.Hid.RawData); // PrintLine($"Left({Program.Gamepad.AxisLeft.rawX},{Program.Gamepad.AxisLeft.rawY})::Right({Program.Gamepad.AxisRight.rawX},{Program.Gamepad.AxisRight.rawY})"); } }
private static void MouseWheelScroll(RawInputData data) { var lRect = NotifyIconHelper.GetIconRect(notifyIconLeft); var rRect = NotifyIconHelper.GetIconRect(notifyIconRight); if (NotifyIconHelper.InRect(Cursor.Position, lRect) || NotifyIconHelper.InRect(Cursor.Position, rRect)) { ScrollVirtualDesktop((data as RawInputMouseData).Mouse); } }
// Raw Input Data --> Schemed User Input Data private UserInputData GetSchemedPcUserInputData(RawInputData rawInputData, User user) { InputSchemes.PCAxisScheme axisScheme = Array.Find(_inputSchemes.pCAxisSchemes, p => p.name == user.userData.settingsData.pcAxisInputScheme); if (axisScheme == null) { axisScheme = _inputSchemes.pCAxisSchemes[0]; } InputSchemes.PCButtonScheme buttonScheme = Array.Find(_inputSchemes.pCButtonSchemes, p => p.name == user.userData.settingsData.pcButtonInputScheme); if (buttonScheme == null) { buttonScheme = _inputSchemes.pCButtonSchemes[0]; } UserInputData userInputState = new UserInputData(); InputSchemes.PCAxisScheme.AxisConversion moveAxisConversion = Array.Find(axisScheme.conversions, p => p.userAxis == UserAxis.Move); if (moveAxisConversion != null) { userInputState.move = rawInputData.GetPCAxis(moveAxisConversion.pCAxis); } InputSchemes.PCAxisScheme.AxisConversion lookAxisConversion = Array.Find(axisScheme.conversions, p => p.userAxis == UserAxis.Look); if (lookAxisConversion != null) { userInputState.look = rawInputData.GetPCAxis(lookAxisConversion.pCAxis); } InputSchemes.PCButtonScheme.ButtonConversion actionAButtonConversion = Array.Find(buttonScheme.conversions, p => p.userButton == UserButton.ActionA); if (actionAButtonConversion != null) { userInputState.actionA = rawInputData.GetPCButton(actionAButtonConversion.pCButton); } InputSchemes.PCButtonScheme.ButtonConversion actionBButtonConversion = Array.Find(buttonScheme.conversions, p => p.userButton == UserButton.ActionB); if (actionBButtonConversion != null) { userInputState.actionB = rawInputData.GetPCButton(actionBButtonConversion.pCButton); } InputSchemes.PCButtonScheme.ButtonConversion actionXButtonConversion = Array.Find(buttonScheme.conversions, p => p.userButton == UserButton.ActionX); if (actionXButtonConversion != null) { userInputState.actionX = rawInputData.GetPCButton(actionXButtonConversion.pCButton); } InputSchemes.PCButtonScheme.ButtonConversion menuButtonConversion = Array.Find(buttonScheme.conversions, p => p.userButton == UserButton.Menu); if (menuButtonConversion != null) { userInputState.menu = rawInputData.GetPCButton(menuButtonConversion.pCButton); } return(userInputState); }
public virtual void OnDeviceEvent(RawInputData data) { GUIOnDeviceEvent?.Invoke(data); if (Connector == null) { return; } if (Connector.IsConnected) { Connector?.SendMessage(MessageGenerator.GenerateByteArray(data)); } }
protected override void WndProc(ref Message m) { const int WM_INPUT = 0x00FF; if (m.Msg == WM_INPUT) { var data = RawInputData.FromHandle(m.LParam); Input?.Invoke(this, new RawInputEventArgs(data)); } base.WndProc(ref m); }
private static void ProcessInput(RawInputData data) { var hidData = data as RawInputHidData; if (hidData == null) { return; } foreach (var mapping in GetMappingsForDevice(hidData.Device)) { ProcessInputMapping(hidData, mapping); } }
protected override void WndProc(ref Message m) { const int WM_INPUT = 0x00FF; if (m.Msg == WM_INPUT) { var data = RawInputData.FromHandle(m.LParam); Input?.Invoke(this, new RawInputEventArgs(data)); } Console.WriteLine("[+]uMsg: " + m.Msg + ", hwnd: " + m.HWnd + ", wParam: " + m.WParam + ", lParam: {0:x}", m.LParam.ToInt32()); base.WndProc(ref m); }
protected override void WndProc(ref Message m) { const int WM_INPUT = 0x00FF; if (m.Msg == WM_INPUT) { RawInputData data = RawInputData.FromHandle(m.LParam); if (Input != null) { Input(data); } } base.WndProc(ref m); }
// Raw Input --> User? // True: Raw Input Data --> Schemed User Input Data --> User // False : Login, break internal void ResolveUserInput(RawInputData rawInputData) { //User pCUSer = TryGetUserByInput(0, InputType.PC, rawInputData.pC.hasButtonDown); //if (pCUSer != null) //{ // //UserInputData userInputState = GetSchemedPcUserInputData(rawInputData, pCUSer); // // pCUSer.TrySetInput(userInputState); //} User touchUser = TryGetUserByInput(0, InputType.Touch, rawInputData.touch.hasButtonDown); if (touchUser != null) { UserInputData userInputState = GetSchemedTouchUserInputState(rawInputData, touchUser); touchUser.TrySetInput(userInputState); } foreach (RawInputData.NSwitch.Controller controller in rawInputData.nSwitch.controllers) { User nSwitchUser = TryGetUserByInput(controller.id, InputType.NSwitch, controller.hasButtonDown); if (nSwitchUser != null) { UserInputData userInputState = GetSchemedNSwitchUserInputState(rawInputData, nSwitchUser); nSwitchUser.TrySetInput(userInputState); } } foreach (RawInputData.XboxOne.Controller controller in rawInputData.xboxOne.controllers) { User xboxOneUser = TryGetUserByInput(controller.id, InputType.XboxOne, controller.hasButtonDown); if (xboxOneUser != null) { UserInputData userInputState = GetSchemedXboxOneUserInputState(rawInputData, xboxOneUser); xboxOneUser.TrySetInput(userInputState); } } foreach (RawInputData.Playstation4.Controller controller in rawInputData.playstation4.controllers) { User playstation4User = TryGetUserByInput(controller.id, InputType.Playstation4, controller.hasButtonDown); if (playstation4User != null) { UserInputData userInputState = GetSchemedPlaystation4UserInputState(rawInputData, playstation4User); playstation4User.TrySetInput(userInputState); } } }
protected override void WndProc(ref Message m) { const int WM_INPUT = 0x00FF; const int WM_CHAR = 0x0102; if (m.Msg == WM_INPUT) { var data = RawInputData.FromHandle(m.LParam); Input?.Invoke(this, new RawInputEventArgs(data)); } else if (m.Msg == WM_CHAR) { ImGui.GetIO().AddInputCharacter((uint)m.WParam.ToInt64()); } base.WndProc(ref m); }
private void SpongeOnWndProcCalled(object sender, Message message) { if (message.Msg != WM_INPUT) { return; } RawInputData data = RawInputData.FromHandle(message.LParam); switch (data) { case RawInputMouseData mouse: HandleMouseData(data, mouse); break; case RawInputKeyboardData keyboard: HandleKeyboardData(data, keyboard); break; } }
public static Thread JoystickListenerThread(OnDeviceEvent onDeviceEventCallback, string deviceIdFilter = null) { Thread joystickListenerThread = new Thread(() => { var joystick = new RawInputReceiverWindow(); RawInputData previousMessage = null; joystick.Input += (sender, e) => { if (deviceIdFilter != e.Data.Header.DeviceHandle.ToString()) { return; } if (previousMessage?.ToString() == e.Data.ToString()) { return; } dynamic dataObject = e.Data; if (dataObject.Hid.Count > 1) { return; } previousMessage = e.Data; onDeviceEventCallback(e.Data); }; try { // Register the HidUsageAndPage to watch any device. RawInputDevice.RegisterDevice(HidUsageAndPage.Joystick, RawInputDeviceFlags.ExInputSink, joystick.Handle); Application.Run(); } finally { RawInputDevice.UnregisterDevice(HidUsageAndPage.Joystick); } }); joystickListenerThread.Priority = ThreadPriority.Highest; joystickListenerThread.Start(); return(joystickListenerThread); }
protected override void WndProc(ref Message m) { const int WM_INPUT = 0x00FF; if (m.Msg == WM_INPUT) { var data = RawInputData.FromHandle(m.LParam); if (data is RawInputMouseData mouseData) { var mouse = mouseData.Mouse; inputHandler.Handle(new MouseInput(mouse.LastX, mouse.LastY, mouse.ButtonData, (MouseFlags)mouse.Flags, (MouseButton)mouse.Buttons)); } else if (data is RawInputKeyboardData keyboardData) { var keyboard = keyboardData.Keyboard; inputHandler.Handle(new KeyboardInput(keyboard.VirutalKey, keyboard.ScanCode, (KeyboardFlags)keyboard.Flags)); } } base.WndProc(ref m); }
private IntPtr MessageSink(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { const int WM_INPUT = 0x00FF; if (msg == WM_INPUT) { var data = RawInputData.FromHandle(lParam); Logger.Trace(data); switch (data) { case RawInputKeyboardData keyboard: ParseKeyboardGestures(keyboard); break; case RawInputMouseData mouse: ParseMouseGestures(mouse); break; } } return(IntPtr.Zero); }
public static Thread KeyboardListenerThread(OnDeviceEvent onDeviceEventCallback, string deviceIdFilter = null) { Thread keyboardListenerThread = new Thread(() => { var keyboard = new RawInputReceiverWindow(); RawInputData previousMessage = null; keyboard.Input += (sender, e) => { if (deviceIdFilter != e.Data.Header.DeviceHandle.ToString()) { return; } if (previousMessage?.ToString() == e.Data.ToString()) { return; } previousMessage = e.Data; onDeviceEventCallback(e.Data); }; try { // Register the HidUsageAndPage to watch any device. RawInputDevice.RegisterDevice(HidUsageAndPage.Keyboard, RawInputDeviceFlags.ExInputSink, keyboard.Handle); Application.Run(); } finally { RawInputDevice.UnregisterDevice(HidUsageAndPage.Keyboard); } }); keyboardListenerThread.Priority = ThreadPriority.Highest; keyboardListenerThread.Start(); return(keyboardListenerThread); }
public void OnDeviceEvent(RawInputData message) { StreamOutputText += message + "\n"; }
public static extern int GetRawInputData(IntPtr hDevice, DataType uiCommand, out RawInputData pData, ref int pcbSize, int cbSizeHeader);
public RawInputEventArgs(RawInputData data) { Data = data; }
/// <summary> /// Sets text box text and tag. /// </summary> /// <param name="key"></param> private void SetTextBoxText(string text, RawInputData data) { Application.Current.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action(() => { bool save = true; var txt = GetActiveTextBox(); if (txt == null) { return; } // Ignore first if (txt == _lastActiveTextBox) { string path = "null"; if (data != null && data.Device != null && data.Device.DevicePath != null) { path = data.Device.DevicePath; } var button = new RawInputButton { DevicePath = path, DeviceType = RawDeviceType.None, MouseButton = RawMouseButton.None, KeyboardKey = Keys.None }; if (data is RawInputMouseData) { RawInputMouseData mouse = data as RawInputMouseData; button.MouseButton = GetButtonFromFlags(mouse.Mouse.Buttons); button.DeviceType = RawDeviceType.Mouse; } else if (data is RawInputKeyboardData) { RawInputKeyboardData kb = data as RawInputKeyboardData; button.KeyboardKey = (Keys)kb.Keyboard.VirutalKey; button.DeviceType = RawDeviceType.Keyboard; if (button.KeyboardKey == Keys.Escape) { save = false; } } // Save? if (save) { txt.ToolTip = text; txt.Text = text; var t = txt.Tag as JoystickButtons; t.RawInputButton = button; t.BindNameRi = text; } else { txt.ToolTip = ""; txt.Text = ""; } // Unfocus textbox Keyboard.ClearFocus(); FocusManager.SetFocusedElement(Application.Current.Windows[0], null); _lastActiveTextBox = null; } else { _lastActiveTextBox = txt; } })); }
protected IntPtr Hook(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam, ref bool handled) { const int WM_INPUT = 0x00FF; // You can read inputs by processing the WM_INPUT message. if (msg == WM_INPUT) { // Create an RawInputData from the handle stored in lParam. var data = RawInputData.FromHandle(lparam); // You can identify the source device using Header.DeviceHandle or just Device. //var sourceDeviceHandle = data.Header.DeviceHandle; //var sourceDevice = data.Device; // The data will be an instance of either RawInputMouseData, RawInputKeyboardData, or RawInputHidData. // They contain the raw input data in their properties. switch (data) { case RawInputMouseData mouse: //RawInput only gives relative mouse movement value.. cheating here with Winform library. var M = System.Windows.Forms.Control.MousePosition; switch (mouse.Mouse.Buttons) { case Linearstar.Windows.RawInput.Native.RawMouseButtonFlags.LeftButtonDown: MouseLBtnDownSimulate(M.X, M.Y); break; case Linearstar.Windows.RawInput.Native.RawMouseButtonFlags.LeftButtonUp: MouseLBtnUpSimulate(M.X, M.Y); break; case Linearstar.Windows.RawInput.Native.RawMouseButtonFlags.RightButtonDown: //issue: click being skipped. //SetupDesktop.MouseRBtnDownSimulate(M.X, M.Y); break; case Linearstar.Windows.RawInput.Native.RawMouseButtonFlags.RightButtonUp: //issue: click being skipped. //SetupDesktop.MouseRBtnUpSimulate(M.X, M.Y); break; case Linearstar.Windows.RawInput.Native.RawMouseButtonFlags.None: MouseMoveSimulate(M.X, M.Y); break; case Linearstar.Windows.RawInput.Native.RawMouseButtonFlags.MouseWheel: /* * https://github.com/ivarboms/game-engine/blob/master/Input/RawInput.cpp * Mouse wheel deltas are represented as multiples of 120. * MSDN: The delta was set to 120 to allow Microsoft or other vendors to build * finer-resolution wheels (a freely-rotating wheel with no notches) to send more * messages per rotation, but with a smaller value in each message. * Because of this, the value is converted to a float in case a mouse's wheel * reports a value other than 120, in which case dividing by 120 would produce * a very incorrect value. * More info: http://social.msdn.microsoft.com/forums/en-US/gametechnologiesgeneral/thread/1deb5f7e-95ee-40ac-84db-58d636f601c7/ */ //Disabled, not tested yet. /* * // One wheel notch is represented as this delta (WHEEL_DELTA). * const float oneNotch = 120; * * // Mouse wheel delta in multiples of WHEEL_DELTA (120). * float mouseWheelDelta = mouse.Mouse.RawButtons; * * // Convert each notch from [-120, 120] to [-1, 1]. * mouseWheelDelta = mouseWheelDelta / oneNotch; * * MouseScrollSimulate(mouseWheelDelta); */ break; } break; } } return(IntPtr.Zero); }
private void HandleMouseData(RawInputData data, RawInputMouseData mouseData) { // Only submit mouse movement 25 times per second but increment the delta // This can create a small inaccuracy of course, but Artemis is not a shooter :') if (mouseData.Mouse.Buttons == RawMouseButtonFlags.None) { _mouseDeltaX += mouseData.Mouse.LastX; _mouseDeltaY += mouseData.Mouse.LastY; if (DateTime.Now - _lastMouseUpdate < TimeSpan.FromMilliseconds(40)) { return; } } ArtemisDevice device = null; string identifier = data.Device?.DevicePath; if (identifier != null) { try { device = _inputService.GetDeviceByIdentifier(this, identifier, InputDeviceType.Keyboard); } catch (Exception e) { _logger.Warning(e, "Failed to retrieve input device by its identifier"); } } // Debug.WriteLine($"Buttons: {data.Mouse.Buttons}, Data: {data.Mouse.ButtonData}, Flags: {data.Mouse.Flags}, XY: {data.Mouse.LastX},{data.Mouse.LastY}"); // Movement if (mouseData.Mouse.Buttons == RawMouseButtonFlags.None) { Win32Point cursorPosition = GetCursorPosition(); OnMouseMoveDataReceived(device, cursorPosition.X, cursorPosition.Y, _mouseDeltaX, _mouseDeltaY); _mouseDeltaX = 0; _mouseDeltaY = 0; _lastMouseUpdate = DateTime.Now; return; } // Now we know its not movement, let the core know there is an identifier so it can store new identifications if applicable if (identifier != null) { OnIdentifierReceived(identifier, InputDeviceType.Mouse); } // Scrolling if (mouseData.Mouse.ButtonData != 0) { if (mouseData.Mouse.Buttons == RawMouseButtonFlags.MouseWheel) { OnMouseScrollDataReceived(device, MouseScrollDirection.Vertical, mouseData.Mouse.ButtonData); } else if (mouseData.Mouse.Buttons == RawMouseButtonFlags.MouseHorizontalWheel) { OnMouseScrollDataReceived(device, MouseScrollDirection.Horizontal, mouseData.Mouse.ButtonData); } return; } // Button presses MouseButton button = MouseButton.Left; bool isDown = false; // Left if (DetermineMouseButton(mouseData, RawMouseButtonFlags.LeftButtonDown, RawMouseButtonFlags.LeftButtonUp, ref isDown)) { button = MouseButton.Left; } // Middle else if (DetermineMouseButton(mouseData, RawMouseButtonFlags.MiddleButtonDown, RawMouseButtonFlags.MiddleButtonUp, ref isDown)) { button = MouseButton.Middle; } // Right else if (DetermineMouseButton(mouseData, RawMouseButtonFlags.RightButtonDown, RawMouseButtonFlags.RightButtonUp, ref isDown)) { button = MouseButton.Right; } // Button 4 else if (DetermineMouseButton(mouseData, RawMouseButtonFlags.Button4Down, RawMouseButtonFlags.Button4Up, ref isDown)) { button = MouseButton.Button4; } else if (DetermineMouseButton(mouseData, RawMouseButtonFlags.Button5Down, RawMouseButtonFlags.Button5Up, ref isDown)) { button = MouseButton.Button5; } OnMouseButtonDataReceived(device, button, isDown); }
public void Setup() { var devices = RawInputDevice.GetDevices(); var hid = devices.OfType <RawInputHid>(); var keyboards = devices.OfType <RawInputKeyboard>(); //RawInputKeyboard keyboard1=keyboards.ElementAt(0); // var window1 = new RawInputReceiverWindow(); var window2 = new RawInputReceiverWindow(); window2.Input += (sender, e) => { // Catch your input here! var data1 = e.Data; RawInputKeyboardData data_2 = (RawInputKeyboardData)data1; // messageBx.Text = data_2.Device.DeviceType.ToString(); // X_axis.Text = data_2.Keyboard.ScanCode.ToString(); // messageBx.Text = data.ToString(); }; // Register the HidUsageAndPage to watch any device. window1.Input += (sender, e) => { // Catch your input here! data = e.Data; data_1 = (RawInputHidData)data; joy_x = data_1.Hid.RawData.ElementAt(4) - 128; joy_y = data_1.Hid.RawData.ElementAt(5) - 128; joy_z = data_1.Hid.RawData.ElementAt(2) - 128; axis_speed = 0.05f; if (data_1.Hid.RawData.ElementAt(7) == 4 || data_1.Hid.RawData.ElementAt(7) == 8) { axis_speed = 0.1f; } // if (data_1.Hid.RawData.ElementAt(4) != 128) // x_axis_var += joy_x * axis_speed; //port.WriteLine("G1 " + "X" + (joy_x * axis_speed) + "F" + fBox.Text); // if (data_1.Hid.RawData.ElementAt(5) != 128) // y_axis_var += joy_y * axis_speed; //Y_axis.Text = y_axis_var.ToString("F3"); // if (data_1.Hid.RawData.ElementAt(2) != 128) // z_axis_var += joy_z * axis_speed; // Z_axis.Text = z_axis_var.ToString("F3"); //Z_axis.Text = data_1.Hid.RawData.ElementAt(6).ToString(); if (port != null && port.IsOpen) { int z_max = 50; int y_max = 50; int x_max = 50; //MessageBox.Show("Joystick is online!"); //v.LeftMotorSpeed = (ushort)(controller.GetState().Gamepad.LeftTrigger * 255); // v.RightMotorSpeed = (ushort)(controller.GetState().Gamepad.RightTrigger * 255); if (joy_x != 0) { if (x_axis_var < x_max) { if (joy_x < 0) { axis_speed = -axis_speed; } //X_axis.Text = x_axis_var.ToString("F3"); //x_axis_var += joy_x * axis_speed; x = axis_speed; //x = speed_xy * x; port.WriteLine("G91"); port.WriteLine("G0 X" + x.ToString("F3") + "F" + fBox.Text); //port.WriteLine("G90"); x_axis_var += x; X_axis.Text = x_axis_var.ToString("F3"); } } if (joy_y != 0) { if (y_axis_var < y_max) { if (joy_y > 0) { axis_speed = -axis_speed; } //y = speed_xy * y; y = axis_speed; port.WriteLine("G91"); port.WriteLine("G0 Y" + y.ToString() + "F" + fBox.Text); //port.WriteLine("G90"); y_axis_var += y; Y_axis.Text = y_axis_var.ToString("F3"); } } if (joy_z != 0) { if (z_axis_var < z_max) { // z = speed_z * z; if (joy_z > 0) { axis_speed = -axis_speed; } z = axis_speed; port.WriteLine("G91"); port.WriteLine("G0 Z" + z.ToString() + "F" + fBox.Text); //port.WriteLine("G90"); z_axis_var += z; Z_axis.Text = z_axis_var.ToString("F3"); } } // controller.SetVibration(v); if (data_1.Hid.RawData.ElementAt(6) == 143) //X buttun { //messageBx.Text = controller.GetState().Gamepad.Buttons + "\r\n"; x_axis_var = 0; X_axis.Text = x_axis_var.ToString("F3"); port.WriteLine("G92 X0"); } if (data_1.Hid.RawData.ElementAt(6) == 31) //Y buttun { //messageBx.Text = controller.GetState().Gamepad.Buttons + "\r\n"; y_axis_var = 0; Y_axis.Text = y_axis_var.ToString("F3"); port.WriteLine("G92 Y0"); } if (data_1.Hid.RawData.ElementAt(6) == 47) //Z buttun { // messageBx.Text = controller.GetState().Gamepad.Buttons + "\r\n"; z_axis_var = 0; Z_axis.Text = z_axis_var.ToString("F3"); port.WriteLine("G92 Z0"); } if (data_1.Hid.RawData.ElementAt(6) == 79) //A buttun { // messageBx.Text = controller.GetState().Gamepad.Buttons + "\r\n"; x_axis_var = 0; X_axis.Text = x_axis_var.ToString("F3"); y_axis_var = 0; Y_axis.Text = y_axis_var.ToString("F3"); z_axis_var = 0; Z_axis.Text = z_axis_var.ToString("F3"); port.WriteLine("G92 X0 Y0 Z0"); } } // set ports //port.WriteLine("G91"); //messageBx.Text += "G91 \r\n"; //port.WriteLine("G1 " + sendBx.Text + "F" + fBox.Text); // messageBx.Text += "G1 " + sendBx.Text + "\r\n"; //port.WriteLine("G90"); //messageBx.Text += "G90 \r\n"; // move the axis }; // RawInputDevice.RegisterDevice(HidUsageAndPage.Keyboard, RawInputDeviceFlags.ExInputSink | RawInputDeviceFlags.NoLegacy, window2.Handle); //RawInputDevice.RegisterDevice(HidUsageAndPage.Joystick, RawInputDeviceFlags.ExInputSink, window1.Handle); //RawInputDevice.UnregisterDevice(HidUsageAndPage.Joystick); //RawInputDevice.UnregisterDevice(HidUsageAndPage.Keyboard); foreach (var device in hid) { if (device.UsageAndPage.Usage == 0x04 || device.UsageAndPage.Usage == 0x05) { string productid = device.ProductId.ToString("X4"); string vendorid = device.VendorId.ToString("X4"); // messageBx.Text += device.ProductName + " ::" + productid + "::" + vendorid + "\r\n";// +device.VendorId:X4+device.ProductId:X4+device.ProductName+device.ManufacturerName; } } }