private void OnTapStart(GestureLayer.TapData data) { try { var properties = BuildProperties(true, false); var modifiers = VirtualKeyModifiers.None; var point = GetPoint(data.X, data.Y); _ownerEvents.RaisePointerPressed( new PointerEventArgs( new Windows.UI.Input.PointerPoint( frameId: GetNextFrameId(), timestamp: (uint)data.Timestamp, device: PointerDevice.For(PointerDeviceType.Touch), pointerId: 0, rawPosition: point, position: point, isInContact: properties.HasPressedButton, properties: properties ), modifiers ) ); } catch (Exception e) { this.Log().Error("Failed to raise PointerPressed", e); } }
private static PointerEventArgs ConvertPointerEvent(Windows.UI.Core.PointerEventArgs e) { var windowsPointerPoint = e.CurrentPoint; var windowsPointerProperties = windowsPointerPoint.Properties; var windowsPointerDevice = windowsPointerPoint.PointerDevice; PointerProperties odysseyPointerProperties = new PointerProperties() { IsLeftButtonPressed = windowsPointerProperties.IsLeftButtonPressed, IsRightButtonPressed = windowsPointerProperties.IsRightButtonPressed, MouseWheelDelta = windowsPointerProperties.MouseWheelDelta }; PointerDevice odysseyPointerDevice = new PointerDevice() { PointerDeviceType = (PointerDeviceType)windowsPointerDevice.PointerDeviceType }; PointerPoint odysseyPointerPoint = new PointerPoint(windowsPointerPoint.PointerId, odysseyPointerProperties, odysseyPointerDevice) { IsInContact = windowsPointerPoint.IsInContact, Position = windowsPointerPoint.Position.ToVector2(), }; PointerEventArgs odysseyPointerEventArgs = new PointerEventArgs(odysseyPointerPoint) { Handled = e.Handled }; return(odysseyPointerEventArgs); }
public static int GetScreenWidth() { var rect = PointerDevice.GetPointerDevices().Last().ScreenRect; var scale = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel; return((int)(rect.Width * scale)); }
private void OnMotionEvent(object o, MotionNotifyEventArgs args) { try { switch (args.Event.Type) { case Gdk.EventType.MotionNotify: _ownerEvents.RaisePointerMoved( new PointerEventArgs( new Windows.UI.Input.PointerPoint( frameId: 0, timestamp: args.Event.Time, device: PointerDevice.For(PointerDeviceType.Mouse), pointerId: 0, rawPosition: new Windows.Foundation.Point(args.Event.X, args.Event.Y), position: new Windows.Foundation.Point(args.Event.X, args.Event.Y), isInContact: false, properties: BuildProperties(args.Event) ) ) ); break; default: Console.WriteLine($"Unknown event: {args.Event.State}"); break; } } catch (Exception e) { this.Log().Error("Failed to raise PointerMoved", e); } }
public PointerPoint GetCurrentPoint(UIElement relativeTo) { var device = PointerDevice.For(PointerDeviceType.Mouse); var rawPosition = _nativeEvent.LocationInWindow; var position = relativeTo != null? relativeTo.ConvertPointFromView(_nativeEvent.LocationInWindow, null) : rawPosition; var properties = new PointerPointProperties() { IsInRange = true, IsPrimary = true, IsLeftButtonPressed = ((int)NSEvent.CurrentPressedMouseButtons & LeftMouseButtonMask) == LeftMouseButtonMask, IsRightButtonPressed = ((int)NSEvent.CurrentPressedMouseButtons & RightMouseButtonMask) == RightMouseButtonMask, }; if (Pointer.PointerDeviceType == PointerDeviceType.Pen) { properties.XTilt = (float)_nativeEvent.Tilt.X; properties.YTilt = (float)_nativeEvent.Tilt.Y; properties.Pressure = (float)_nativeEvent.Pressure; } return(new PointerPoint( FrameId, ToTimeStamp(_nativeEvent.Timestamp), device, Pointer.PointerId, rawPosition, position, Pointer.IsInContact, properties)); }
/// <summary> /// Passes pointer (Mouse/Touch/Tablet) inputs to the DOM window /// </summary> protected void Handle_Pointer_Input(PointerDevice Device, EPointerInputType InputType) { Event RetEvent = null; switch (InputType) { case EPointerInputType.Moved: { } break; case EPointerInputType.ButtonPress: { } break; case EPointerInputType.ButtonRelease: { } break; default: { throw new NotImplementedException($"No logic implemented for {nameof(EPointerInputType)} value \"{InputType}\""); } } dispatchEvent(RetEvent); }
public static void InitializeSkiInputService(this Page _) { var window = CoreWindow.GetForCurrentThread(); SkiInputService.Instance.CalculateNumberOfMousePointersFunc = () => PointerDevice .GetPointerDevices() .Count(pointer => pointer.PointerDeviceType == PointerDeviceType.Mouse); SkiInputService.Instance.IsInputViewFocusedFunc = () => FocusManager.GetFocusedElement() is TextBox; window.Dispatcher.AcceleratorKeyActivated += (sender, args) => { var intKey = (int)args.VirtualKey; var skiVirtualKey = (SkiVirtualKey)intKey; var keyState = window.GetKeyState(args.VirtualKey); if (keyState.HasFlag(CoreVirtualKeyStates.Down)) { SkiInputService.Instance.OnKeyDown(skiVirtualKey); } else { SkiInputService.Instance.OnKeyUp(skiVirtualKey); } }; }
private void OnPointerPressed(CoreWindow window, PointerEventArgs args) { PointerPoint p = args.CurrentPoint; PointerDevice device = p.PointerDevice; switch (device.PointerDeviceType) { case PointerDeviceType.Touch: case PointerDeviceType.Pen: { TouchDown(this, (int)p.Position.X, (int)p.Position.Y, p.PointerId); break; } case PointerDeviceType.Mouse: { ulong time = p.Timestamp; ulong elapsedTime = (time - _lastClickTime) / 1000; Noesis.MouseButton button = MouseButton(p.Properties); if (elapsedTime <= (ulong)GetDoubleClickTime() && button == _lastClickButton) { MouseDoubleClick(this, (int)p.Position.X, (int)p.Position.Y, button); _lastClickTime = 0; } else { MouseButtonDown(this, (int)p.Position.X, (int)p.Position.Y, button); _lastClickTime = time; } _lastClickButton = button; break; } } }
private void OnWindowLeaveEvent(object o, LeaveNotifyEventArgs args) { try { var properties = BuildProperties(args.Event); var modifiers = GetKeyModifiers(); _ownerEvents.RaisePointerExited( new PointerEventArgs( new Windows.UI.Input.PointerPoint( frameId: GetNextFrameId(), timestamp: args.Event.Time, device: PointerDevice.For(PointerDeviceType.Mouse), pointerId: 0, rawPosition: new Windows.Foundation.Point(args.Event.X, args.Event.Y), position: new Windows.Foundation.Point(args.Event.X, args.Event.Y), isInContact: properties.HasPressedButton, properties: properties ), modifiers ) ); } catch (Exception e) { this.Log().Error("Failed to raise PointerExited", e); } }
public PointerPoint GetCurrentPoint(UIElement relativeTo) { var timestamp = ToTimeStamp(_nativeEvent.EventTime); var device = PointerDevice.For(Pointer.PointerDeviceType); var(rawPosition, position) = GetPositions(relativeTo); return(new PointerPoint(FrameId, timestamp, device, Pointer.PointerId, rawPosition, position, Pointer.IsInContact, _properties)); }
public PointerPoint GetCurrentPoint(UIElement relativeTo) { var timestamp = ToTimeStamp(_nativeTouch.Timestamp); var device = PointerDevice.For(Pointer.PointerDeviceType); var position = (Point)_nativeTouch.LocationInView(relativeTo); var properties = GetProperties(); return(new PointerPoint(FrameId, timestamp, device, Pointer.PointerId, position, position, Pointer.IsInContact, properties)); }
public MainPage() { this.InitializeComponent(); // Check if there's a pen among the pointer input devices foreach (PointerDevice device in PointerDevice.GetPointerDevices()) { hasPen |= device.PointerDeviceType == PointerDeviceType.Pen; } }
public PointerPoint GetCurrentPoint(UIElement relativeTo) { var timestamp = ToTimeStamp(_nativeEvent.EventTime); var device = PointerDevice.For(Pointer.PointerDeviceType); var rawPosition = new Point(_nativeEvent.RawX, _nativeEvent.RawY); // Relative to the screen var position = GetPosition(relativeTo); var properties = GetProperties(); return(new PointerPoint(FrameId, timestamp, device, Pointer.PointerId, rawPosition, position, Pointer.IsInContact, properties)); }
public PointerPoint GetCurrentPoint(UIElement relativeTo) { var timestamp = ToTimeStamp(_nativeTouch.Timestamp); var device = PointerDevice.For(Pointer.PointerDeviceType); var rawPosition = (Point)_nativeTouch.GetPreciseLocation(null); var position = relativeTo == null ? rawPosition : (Point)_nativeTouch.GetPreciseLocation(relativeTo); return(new PointerPoint(FrameId, timestamp, device, Pointer.PointerId, rawPosition, position, Pointer.IsInContact, _properties)); }
public PointerPoint GetCurrentPoint(UIElement relativeTo) { var device = PointerDevice.For(PointerDeviceType.Mouse); var point = relativeTo.ConvertPointFromView(_nativeEvent.LocationInWindow, null); var properties = new PointerPointProperties() { IsInRange = true, IsPrimary = true }; return(new PointerPoint(FrameId, _pseudoTimestamp, device, 0, point, point, true, properties)); }
public PointerPoint GetCurrentPoint(UIElement relativeTo) { var timestamp = ToTimeStamp(_timestamp); var device = PointerDevice.For(Pointer.PointerDeviceType); var position = relativeTo == null ? _absolutePosition : relativeTo.TransformToVisual(null).Inverse.TransformPoint(_absolutePosition); var properties = GetProperties(); return(new PointerPoint(FrameId, timestamp, device, Pointer.PointerId, position, position, Pointer.IsInContact, properties)); }
public PointerPoint GetCurrentPoint(UIElement relativeTo) { var device = PointerDevice.For(PointerDeviceType.Mouse); var position = relativeTo == null ? _absolutePosition : relativeTo.TransformToVisual(null).Inverse.TransformPoint(_absolutePosition); var properties = _pointerEventArgs.CurrentPoint.Properties; return(new PointerPoint(FrameId, _pseudoTimestamp, device, 0, _absolutePosition, position, true, properties)); }
/// <summary> /// 获取设备屏幕大小 /// </summary> /// <returns></returns> private static Size GetDeviceScreenSize() { Size resolution = Size.Empty; foreach (var item in PointerDevice.GetPointerDevices()) { resolution.Width = item.ScreenRect.Width; resolution.Height = item.ScreenRect.Height; break; } return(resolution); }
public PointerPoint GetCurrentPoint(UIElement relativeTo) { var device = PointerDevice.For(PointerDeviceType.Mouse); var translation = relativeTo.TransformToVisual(null) as TranslateTransform; var offset = new Point(_point.X - translation.X, _point.Y - translation.Y); var properties = new PointerPointProperties() { IsInRange = true, IsPrimary = true }; return(new PointerPoint(FrameId, _pseudoTimestamp, device, 0, offset, offset, true, properties)); }
private void OnPointerWheel(CoreWindow window, PointerEventArgs args) { PointerPoint p = args.CurrentPoint; PointerDevice device = p.PointerDevice; if (p.Properties.IsHorizontalMouseWheel) { MouseHWheel(this, (int)p.Position.X, (int)p.Position.Y, p.Properties.MouseWheelDelta); } else { MouseWheel(this, (int)p.Position.X, (int)p.Position.Y, p.Properties.MouseWheelDelta); } }
private static PointerPoint GetPointerPoint(NSEvent nativeEvent, Point posInWindow) { var frameId = ToFrameId(nativeEvent.Timestamp); var timestamp = ToTimestamp(nativeEvent.Timestamp); var pointerDeviceType = GetPointerDeviceType(nativeEvent); var pointerDevice = PointerDevice.For(pointerDeviceType); var pointerId = pointerDeviceType == PointerDeviceType.Pen ? (uint)nativeEvent.PointingDeviceID() : (uint)0; var isInContact = GetIsInContact(nativeEvent); var properties = GetPointerProperties(nativeEvent, pointerDeviceType); return(new PointerPoint(frameId, timestamp, pointerDevice, pointerId, posInWindow, posInWindow, isInContact, properties)); }
public MainPage() { this.InitializeComponent(); // Check if there's a pen among the pointer input devices foreach (PointerDevice device in PointerDevice.GetPointerDevices()) { hasPen |= device.PointerDeviceType == PointerDeviceType.Pen; } // Default drawing attributes inkDrawingAttributes.Color = Colors.Blue; inkDrawingAttributes.Size = new Size(6, 6); inkManager.SetDefaultDrawingAttributes(inkDrawingAttributes); }
private void UpdatePointerCapabilities() { var devices = PointerDevice.GetPointerDevices(); if (PointerIntegratedDevicesOnly) { devices = devices.Where(x => x.IsIntegrated).ToList(); } IsTouchAvailable = devices.Any(x => x.PointerDeviceType == PointerDeviceType.Touch); IsMouseAvailable = devices.Any(x => x.PointerDeviceType == PointerDeviceType.Mouse); IsPenAvailable = devices.Any(x => x.PointerDeviceType == PointerDeviceType.Pen); PointerSupportTouch = IsTouchAvailable; PointerSupportMouse = IsMouseAvailable; PointerSupportPen = IsPenAvailable; }
private void OnPointerWheel(CoreWindow window, PointerEventArgs args) { PointerPoint p = args.CurrentPoint; PointerDevice device = p.PointerDevice; double scale = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel; int x = (int)(scale * p.Position.X); int y = (int)(scale * p.Position.Y); if (p.Properties.IsHorizontalMouseWheel) { MouseHWheel(this, x, y, p.Properties.MouseWheelDelta); } else { MouseWheel(this, x, y, p.Properties.MouseWheelDelta); } }
internal PointerPoint( uint frameId, ulong timestamp, PointerDevice device, uint pointerId, Point rawPosition, Point position, bool isInContact, PointerPointProperties properties) { FrameId = frameId; Timestamp = timestamp; PointerDevice = device; PointerId = pointerId; RawPosition = rawPosition; Position = position; IsInContact = isInContact; Properties = properties; }
private static PointerEventArgs BuildPointerArgs(NSEvent nativeEvent, Point posInWindow) { var frameId = ToFrameId(nativeEvent.Timestamp); var timestamp = ToTimestamp(nativeEvent.Timestamp); var pointerDeviceType = GetPointerDeviceType(nativeEvent); var pointerDevice = PointerDevice.For(pointerDeviceType); var pointerId = pointerDeviceType == PointerDeviceType.Pen ? (uint)nativeEvent.PointingDeviceID() : (uint)1; var isInContact = GetIsInContact(nativeEvent); var properties = GetPointerProperties(nativeEvent, pointerDeviceType).SetUpdateKindFromPrevious(_previous?.CurrentPoint.Properties); var modifiers = GetVirtualKeyModifiers(nativeEvent); var point = new PointerPoint(frameId, timestamp, pointerDevice, pointerId, posInWindow, posInWindow, isInContact, properties); var args = new PointerEventArgs(point, modifiers); _previous = args; return(args); }
private void OnPointerMoved(CoreWindow window, PointerEventArgs args) { PointerPoint p = args.CurrentPoint; PointerDevice device = p.PointerDevice; switch (device.PointerDeviceType) { case PointerDeviceType.Touch: case PointerDeviceType.Pen: { TouchMove(this, (int)p.Position.X, (int)p.Position.Y, p.PointerId); break; } case PointerDeviceType.Mouse: { MouseMove(this, (int)p.Position.X, (int)p.Position.Y); break; } } }
private void OnPointerReleased(CoreWindow window, PointerEventArgs args) { PointerPoint p = args.CurrentPoint; PointerDevice device = p.PointerDevice; switch (device.PointerDeviceType) { case PointerDeviceType.Touch: case PointerDeviceType.Pen: { TouchUp(this, (int)p.Position.X, (int)p.Position.Y, p.PointerId); break; } case PointerDeviceType.Mouse: { MouseButtonUp(this, (int)p.Position.X, (int)p.Position.Y, MouseButton(p.Properties)); break; } } }
/// <summary> /// 获取设备屏幕长宽 /// </summary> /// <returns></returns> public static Size GetDeviceResolution() { //using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero)) //{ // float dpiX = graphics.DpiX; // float dpiY = graphics.DpiY; //} //using (ManagementClass mc = new ManagementClass("Win32_DesktopMonitor")) //{ // using (ManagementObjectCollection moc = mc.GetInstances()) // { // int PixelsPerXLogicalInch = 0; // dpi for x // int PixelsPerYLogicalInch = 0; // dpi for y // foreach (ManagementObject each in moc) // { // PixelsPerXLogicalInch = int.Parse((each.Properties["PixelsPerXLogicalInch"].Value.ToString())); // PixelsPerYLogicalInch = int.Parse((each.Properties["PixelsPerYLogicalInch"].Value.ToString())); // } // Console.WriteLine("PixelsPerXLogicalInch:" + PixelsPerXLogicalInch.ToString()); // Console.WriteLine("PixelsPerYLogicalInch:" + PixelsPerYLogicalInch.ToString()); // Console.Read(); // } //} Size resolution = Size.Empty; //var rawPixelsPerViewPixel = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel; //var DPI = DisplayInformation.GetForCurrentView().RawDpiX; foreach (var item in PointerDevice.GetPointerDevices()) { resolution.Width = item.ScreenRect.Width; resolution.Height = item.ScreenRect.Height; break; } return(resolution); }
void InitializeWindow() { try { if (Window.Current != null && Window.Current.Content != null) { var bounds = Window.Current.Bounds; double w, h; var pointerDevice = PointerDevice.GetPointerDevices().FirstOrDefault(); if (pointerDevice != null) { w = pointerDevice.ScreenRect.Width; h = pointerDevice.ScreenRect.Height; } else { w = bounds.Width; h = bounds.Height; } var displayInfo = DisplayInformation.GetForCurrentView(); var scale = (double)(int)displayInfo.ResolutionScale / 100d; w = Math.Round(w * scale); h = Math.Round(h * scale); if ((displayInfo.NativeOrientation & DisplayOrientations.Landscape) == DisplayOrientations.Landscape) { ScreenResolution = new Dimensions((int)w, (int)h); } else // portrait { ScreenResolution = new Dimensions((int)h, (int)w); } ViewPortResolution = new Dimensions((int)bounds.Width, (int)bounds.Height); // leave viewport at the scale unadjusted size Window.Current.SizeChanged += Current_SizeChanged; windowInitialized = true; } } catch { /* ignore, Bounds may not be ready yet */ } }