public static void CursorRemoved(TouchCursor b) { if (mutex.WaitOne(TimeSpan.FromSeconds(0.0), false)) { _window.Dispatcher.BeginInvoke(DispatcherPriority.Input, (Action)(() => { System.Diagnostics.Debug.WriteLine(b.ID + "up"); if (!Contacts.ContainsKey(b.ID)) { CursorAdded(b); } var device = Contacts[b.ID]; if (device == null || !device.IsActive) { return; } device.Position = new Point(b.X, b.Y); device.width = b.Width; device.height = b.Height; device.ReportUp(); device.Deactivate(); Contacts.Remove(b.ID); })); } }
public static void CursorAdded(TouchCursor b) { if (mutex.WaitOne(TimeSpan.FromSeconds(0.0), false)) { _window.Dispatcher.BeginInvoke(DispatcherPriority.Input, (Action)(() => { System.Diagnostics.Debug.WriteLine(b.ID + "down"); if (Contacts.ContainsKey(b.ID)) { return; } var device = new TouchProvider(b.ID); device.SetActiveSource(PresentationSource.FromVisual(_window)); device.Position = new Point(b.X, b.Y); device.width = b.Width; device.height = b.Height; device.Activate(); device.ReportDown(); if (!Contacts.ContainsKey(b.ID)) { Contacts.Add(b.ID, device); } })); } }
static void timer_Tick(object sender, EventArgs e) { if (mutex == null) { mutex = new Mutex(false, "test"); } if (mutex.WaitOne(TimeSpan.FromSeconds(0.0), false)) { System.Diagnostics.Debug.WriteLine("------------------------------------"); int num = r.Next(MaxDownPointsFrame + 1); for (int i = 0; i < num; i++) { System.Diagnostics.Debug.WriteLine(i.ToString() + "down point"); CursorAdded(TouchCursor.GetRandomCursor(GetAvailableID(), _w, _h)); } for (int i = 0; i < Contacts.Count; i++) { double probability = r.NextDouble(); if (probability < UpRate) { TouchProvider tp = Contacts.ElementAt(i).Value as TouchProvider; TouchCursor tc = new TouchCursor(tp.Id, tp.Position.X, tp.Position.Y); CursorRemoved(tc); } else { TouchProvider tp = Contacts.ElementAt(i).Value as TouchProvider; double nx = tp.Position.X; double ny = tp.Position.Y; if (r.NextDouble() < 0.5) { nx += MaxUpdateDistance * r.NextDouble(); if (nx >= _w) { nx = _w - 1; } } else { nx -= MaxUpdateDistance * r.NextDouble(); if (nx < 0) { nx = 0; } } if (r.NextDouble() < 0.5) { ny += MaxUpdateDistance * r.NextDouble(); if (ny > _h - 1) { ny = _h - 1; } } else { ny -= MaxUpdateDistance * r.NextDouble(); if (ny < 0) { ny = 0; } } } } } }