private bool ProcessKeyboardEvent(BaseHook.KeyState keyState, uint key) { var windowtitle = Win32Utils.GetActiveWindowTitle(); if (windowtitle != this.Title) { return(false); } CursorPoint mPoint = GetCurrentMousePosition(); if (mPoint == null) { return(false); } if (this.isInterceptKey((Keys)key)) { return(false); } KeyboardEvent kEvent = new KeyboardEvent { Key = (Keys)key, Action = (keyState == BaseHook.KeyState.Keydown) ? Constants.KEY_DOWN : Constants.KEY_UP }; //Console.WriteLine("添加键盘事件:" + JsonConvert.SerializeObject(kEvent)); LogKeyboardEvents(kEvent); return(false); }
/// <summary> /// 创建鼠标移动特征 /// </summary> private void CreateMouseMotionCharacteristic() { mouseMotionCharacteristic = controllerService.AddCharacteristic ( RemoteUuids.MouseMotionCharacteristicGuid, CharacteristicProperties.Notify | CharacteristicProperties.Read, GattPermissions.Read ); mouseMotionCharacteristic.WhenDeviceSubscriptionChanged().Subscribe(e => { ; //当订阅发生改变时 }); mouseMotionCharacteristic.WhenReadReceived().Subscribe(x => { if (OnReadReceived != null) { cursorPoint = OnReadReceived(); } byte[] posDataBytes = new byte[2 * sizeof(double)]; var xBytes = BitConverter.GetBytes(cursorPoint.X); var yBytes = BitConverter.GetBytes(cursorPoint.Y); System.Diagnostics.Debug.WriteLine(cursorPoint.X.ToString() + ", " + cursorPoint.Y.ToString()); xBytes.CopyTo(posDataBytes, 0); yBytes.CopyTo(posDataBytes, sizeof(double)); x.Value = posDataBytes; x.Status = GattStatus.Success; }); }
private bool ProcessMouseEvent(MouseHook.MouseEvents mAction, int mValue) { var windowtitle = Win32Utils.GetActiveWindowTitle(); if (windowtitle != this.Title) { return(false); } CursorPoint mPoint = GetCurrentMousePosition(); if (mPoint == null) { return(false); } MouseEvent mEvent = new MouseEvent { Location = mPoint, Action = mAction, Value = mValue }; //Console.WriteLine("添加鼠标事件:" + JsonConvert.SerializeObject(mEvent)); LogMouseEvents(mEvent); return(false); }
private void PlaybackMouse(Record record) { //pipeClient.SendRequest(record); //return; CursorPoint newPos = record.EventMouse.Location; MouseHook.MouseEvents mEvent = record.EventMouse.Action; MouseUtils.PerformMouseEvent(mEvent, newPos); }
private bool ShowUsage() { CursorPoint cursorPos = new CursorPoint(); try { return GetPhysicalCursorPos(ref cursorPos); } catch (EntryPointNotFoundException) // Not Windows Vista { return false; } }
private void TouchpadPanGestureRecongnizer_PanUpdated(object sender, PanUpdatedEventArgs e) { sendTimeSpan.Start(); CursorPoint = new CursorPoint { X = e.TotalX, Y = e.TotalY }; if ((CursorPoint.X == 0 && CursorPoint.Y == 0) || sendTimeSpan.ElapsedMilliseconds > 50) { App.ControllerService.SendMousePostion(CursorPoint); sendTimeSpan.Reset(); } }
public void SendMousePostion(CursorPoint cursorPoint) { byte[] posDataBytes = new byte[2 * sizeof(double)]; var xBytes = BitConverter.GetBytes(cursorPoint.X); var yBytes = BitConverter.GetBytes(cursorPoint.Y); xBytes.CopyTo(posDataBytes, 0); yBytes.CopyTo(posDataBytes, sizeof(double)); try { Parallel.ForEach(mouseMotionCharacteristic.SubscribedDevices, device => mouseMotionCharacteristic.Broadcast(posDataBytes, device)); } catch { ; } }
public void CursorPointTriggered() { repairPhaseHandler.IncreaseTaskProgress(); if (repairPhaseHandler.currentTaskProgress == 0) // Would only equal 0 if we moved on to the next task { Destroy(gameObject); return; } currentSpawnPoint++; if (currentSpawnPoint >= spawnPointHolder.childCount) { currentSpawnPoint = 0; } CursorPoint newCursorPoint = Instantiate(cursorPoint, spawnPointHolder.GetChild(currentSpawnPoint).position, Quaternion.identity).GetComponent <CursorPoint>(); newCursorPoint.cursorPointSpawner = this; }
private async void ReadCursorPoints() { while (true) { try { var result = await mouseMotionCharacteristic.ReadValueAsync(); if (result.Status != GattCommunicationStatus.Success) { continue; } System.Diagnostics.Debug.WriteLine(result.Status.ToString()); using (var reader = DataReader.FromBuffer(result.Value)) { byte[] bytesData = new byte[2 * sizeof(double)]; reader.ReadBytes(bytesData); CursorPoint cursorPoint = new CursorPoint { X = BitConverter.ToDouble(bytesData, 0), Y = BitConverter.ToDouble(bytesData, sizeof(double)) }; System.Diagnostics.Debug.WriteLine(cursorPoint.X.ToString() + ", " + cursorPoint.Y.ToString()); if (cursorPoint.X == 0 && cursorPoint.Y == 0) { oldCursorPoint = cursorPoint; continue; } var moveX = (cursorPoint.X - oldCursorPoint.X); var moveY = (cursorPoint.Y - oldCursorPoint.Y); mouseSimulator.MoveMouseBy((int)moveX, (int)moveY); oldCursorPoint = cursorPoint; } } catch { ; } } }
public static CursorPoint CursorPointInformation(DockPanel dockPanel, IDockDragSource dragSource) { FloatWindow sourceFloatWindow = dragSource as FloatWindow; CursorPoint info = new CursorPoint(); info.DragSource = dragSource; info.Cursor = Control.MousePosition; // find the window beneath the cursor int currentProcessId = System.Diagnostics.Process.GetCurrentProcess().Id; NativeMethods.EnumWindows((hWnd, arg) => { uint processId; NativeMethods.GetWindowThreadProcessId(hWnd, out processId); if (processId == currentProcessId) { if (sourceFloatWindow != null && sourceFloatWindow.Handle == hWnd) { // ignore the source floating window return(true); } Control window = Control.FromHandle(hWnd); if (window != null && window.Visible && ControlContains(window, info.Cursor)) { // look into child controls if (SearchChilds(window, info, dockPanel)) { return(false); } } } return(true); }, IntPtr.Zero); return(info); }
private static extern bool GetCursorPos(out CursorPoint lpPoint);
internal static extern bool PhysicalToLogicalPoint(IntPtr hWnd, ref CursorPoint lpPoint);
internal static extern bool GetPhysicalCursorPos(ref CursorPoint lpPoint);
private static bool SearchChilds(Control window, CursorPoint info, DockPanel dockPanel) { // enumerate child controls at the cursor point List <Control> childs = new List <Control>(); const uint CWP_SKIPDISABLED = 0x0002; const uint CWP_SKIPINVISIBLE = 0x0001; const uint CWP_SKIPTRANSPARENT = 0x0004; uint flags = CWP_SKIPDISABLED | CWP_SKIPINVISIBLE | CWP_SKIPTRANSPARENT; Control current = window; while (true) { childs.Add(current); IntPtr hwnd = NativeMethods.ChildWindowFromPointEx( current.Handle, current.PointToClient(info.Cursor), flags); if (hwnd == current.Handle || hwnd == IntPtr.Zero) { break; } current = Control.FromHandle(hwnd); if (current == null) { break; } } // make the array deepest first childs.Reverse(); bool targetFound = false; foreach (Control control in childs) { if (info.Pane == null) // not found? { IDockContent content = control as IDockContent; if (content != null && content.DockHandler.DockPanel == dockPanel) { info.Pane = content.DockHandler.Pane; targetFound = true; } DockPane pane = control as DockPane; if (pane != null && pane.DockPanel == dockPanel) { info.Pane = pane; targetFound = true; } } if (info.FloatWindow == null && info.DockPanel == null) // not found? { FloatWindow floatWindow = window as FloatWindow; if (floatWindow != null && floatWindow.DockPanel == dockPanel) { info.FloatWindow = floatWindow; targetFound = true; } DockPanel panel = control as DockPanel; if (panel != null && panel == dockPanel) { info.DockPanel = panel; targetFound = true; } } } return(targetFound); }
private void BtnOk_Click(object sender, RoutedEventArgs e) { int offset = 0; var mouseButton = (MouseKeys)cbxMouseButton.SelectedItem; var mouseAction = (MouseActions)cbxMouseAction.SelectedItem; if (mouseButton == MouseKeys.Left) { offset = 0; } else if (mouseButton == MouseKeys.Right) { offset = 3; } else if (mouseButton == MouseKeys.Middle) { offset = 6; } CursorPoint point = new CursorPoint(x, y); switch (mouseAction) { case MouseActions.Click: mouseEvents = new List <MouseEvent> { new MouseEvent { Location = point, Action = MouseEvents.LeftDown + offset }, new MouseEvent { Location = point, Action = MouseEvents.LeftUp + offset } }; break; case MouseActions.DoubleClick: mouseEvents = new List <MouseEvent> { new MouseEvent { Location = point, Action = MouseEvents.LeftDown + offset }, new MouseEvent { Location = point, Action = MouseEvents.LeftUp + offset }, new MouseEvent { Location = point, Action = MouseEvents.LeftDown + offset }, new MouseEvent { Location = point, Action = MouseEvents.LeftUp + offset } }; break; case MouseActions.Up: mouseEvents = new List <MouseEvent> { new MouseEvent { Location = point, Action = MouseEvents.LeftUp + offset } }; break; case MouseActions.Down: mouseEvents = new List <MouseEvent> { new MouseEvent { Location = point, Action = MouseEvents.LeftDown + offset } }; break; } this.Close(); }
public static extern IntPtr WindowFromPoint(CursorPoint lpPoint);
void Start() { CursorPoint newCursorPoint = Instantiate(cursorPoint, spawnPointHolder.GetChild(currentSpawnPoint).position, Quaternion.identity).GetComponent <CursorPoint>(); newCursorPoint.cursorPointSpawner = this; }
public InputInteractionDescriptor(string text, TwitterStatusBase inReplyTo = null, CursorPoint cp = CursorPoint.Begin, bool setFocus = true) { this.Text = text; this.InReplyTo = inReplyTo; this.NewCursorPoint = cp; this.SetFocus = setFocus; }
private void MouseMotionCharacteristic_ValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args) { using (var reader = DataReader.FromBuffer(args.CharacteristicValue)) { //如果是长按的话 if (stopwatch.IsRunning) { mouseSimulator.LeftButtonDown(); isLeftButtonDown = true; stopwatch.Reset(); } byte[] bytesData = new byte[2 * sizeof(double)]; reader.ReadBytes(bytesData); CursorPoint cursorPoint = new CursorPoint { X = BitConverter.ToDouble(bytesData, 0), Y = BitConverter.ToDouble(bytesData, sizeof(double)) }; System.Diagnostics.Debug.WriteLine("new: " + cursorPoint.X.ToString() + ", " + cursorPoint.Y.ToString()); System.Diagnostics.Debug.WriteLine("new: " + oldCursorPoint.X.ToString() + ", " + oldCursorPoint.Y.ToString()); if (cursorPoint.X == 0 && cursorPoint.Y == 0) { oldCursorPoint = cursorPoint; System.Diagnostics.Debug.WriteLine("归0"); return; } var moveX = (cursorPoint.X - oldCursorPoint.X); var moveY = (cursorPoint.Y - oldCursorPoint.Y); Debug.WriteLine("PC: " + moveX.ToString() + ", " + moveY.ToString()); int movXTotal = 0; int movYTotal = 0; while (true) { bool stopMovingX = false; bool stopMovingY = false; if (moveX == 0) { stopMovingX = true; } if (moveY == 0) { stopMovingY = true; } if (moveX > 0) { if (++movXTotal < moveX) { mouseSimulator.MoveMouseBy(1, 0); } else { stopMovingX = true; } } else if (moveX < 0) { if (--movXTotal > moveX) { mouseSimulator.MoveMouseBy(-1, 0); } else { stopMovingX = true; } } if (moveY > 0) { if (++movYTotal < moveY) { mouseSimulator.MoveMouseBy(0, 1); } else { stopMovingY = true; } } else if (moveY < 0) { if (--movYTotal > moveY) { mouseSimulator.MoveMouseBy(0, -1); } else { stopMovingY = true; } } if (stopMovingX && stopMovingY) { break; } } //mouseSimulator.MoveMouseBy((int)moveX, (int)moveY); oldCursorPoint = cursorPoint; } }
public CodeCursor() { this.HighlightFrom = new CursorPoint(); this.HighlightTo = new CursorPoint(); }