private static void _CheckKeys(TabletOptionButton.ButtonAction action, TabletOptionButton.TabletButton button, bool held) { if (_IsKeypressAction(action)) { _CheckKeys(button, ((int)action >> 16), held); } }
private static void _CheckKeys(TabletOptionButton.TabletButton button, int a, bool held) { byte p = (byte)(a & 0xFF); bool ctrl = (a & (int)Keypress.CTRL_MASK) > 0; bool shift = (a & (int)Keypress.SHIFT_MASK) > 0; bool alt = (a & (int)Keypress.ALT_MASK) > 0; bool win = (a & (int)Keypress.WIN_MASK) > 0; bool sendOnce = (a & (int)Keypress.SEND_ONCE_MASK) > 0; _CheckKeys(button, p, ctrl, shift, alt, win, held, sendOnce); }
private static void _CheckKeys(TabletOptionButton.TabletButton button, byte p, bool ctrl, bool shift, bool alt, bool win, bool held, bool sendOnce) { if (held) { if (!_keyCounters[button].ContainsKey(p)) { _keyCounters[button].Add(p, 0); } if (_keyCounters[button][p] == 0) { if (ctrl && _modifierCounters[Keypress.ModifierKeyCode.Control] == 0) { _modifierCounters[Keypress.ModifierKeyCode.Control]++; keybd_event((byte)Keypress.ModifierKeyCode.Control, 0, 0, UIntPtr.Zero); } if (shift && _modifierCounters[Keypress.ModifierKeyCode.Shift] == 0) { _modifierCounters[Keypress.ModifierKeyCode.Shift]++; keybd_event((byte)Keypress.ModifierKeyCode.Shift, 0, 0, UIntPtr.Zero); } if (alt && _modifierCounters[Keypress.ModifierKeyCode.Alt] == 0) { _modifierCounters[Keypress.ModifierKeyCode.Alt]++; keybd_event((byte)Keypress.ModifierKeyCode.Alt, 0, 0, UIntPtr.Zero); } if (win && _modifierCounters[Keypress.ModifierKeyCode.Windows] == 0) { _modifierCounters[Keypress.ModifierKeyCode.Windows]++; keybd_event((byte)Keypress.ModifierKeyCode.Windows, 0, 0, UIntPtr.Zero); } } //Send the keydown event if (sendOnce && _keyCounters[button][p] == 1) { //Already sent it, do nothing } else { _keyCounters[button][p]++; keybd_event(p, 0, 0, UIntPtr.Zero); } } else { //Send the key up event for the key and each modifier if (_keyCounters[button].ContainsKey(p) && _keyCounters[button][p] > 0) { _keyCounters[button][p]--; keybd_event(p, 0, 2, UIntPtr.Zero); } if (ctrl && _modifierCounters[Keypress.ModifierKeyCode.Control] > 0) { _modifierCounters[Keypress.ModifierKeyCode.Control]--; if (_modifierCounters[Keypress.ModifierKeyCode.Control] == 0) { keybd_event((byte)Keypress.ModifierKeyCode.Control, 0, 2, UIntPtr.Zero); } } if (shift && _modifierCounters[Keypress.ModifierKeyCode.Shift] > 0) { _modifierCounters[Keypress.ModifierKeyCode.Shift]--; if (_modifierCounters[Keypress.ModifierKeyCode.Shift] == 0) { keybd_event((byte)Keypress.ModifierKeyCode.Shift, 0, 2, UIntPtr.Zero); } } if (alt && _modifierCounters[Keypress.ModifierKeyCode.Alt] > 0) { _modifierCounters[Keypress.ModifierKeyCode.Alt]--; if (_modifierCounters[Keypress.ModifierKeyCode.Alt] == 0) { keybd_event((byte)Keypress.ModifierKeyCode.Alt, 0, 2, UIntPtr.Zero); } } if (win && _modifierCounters[Keypress.ModifierKeyCode.Windows] > 0) { _modifierCounters[Keypress.ModifierKeyCode.Windows]--; if (_modifierCounters[Keypress.ModifierKeyCode.Windows] == 0) { keybd_event((byte)Keypress.ModifierKeyCode.Windows, 0, 2, UIntPtr.Zero); } } } }
private static void _PerformAction(TabletConnection conn, TabletOptionButton.TabletButton button, TabletOptionButton.ButtonAction action, bool held) { switch ((TabletOptionButton.ButtonAction)((int)action & 0xFFFF)) { case TabletOptionButton.ButtonAction.LeftClick: mouse_event(held ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP, 0, 0, 0, UIntPtr.Zero); break; case TabletOptionButton.ButtonAction.MiddleClick: mouse_event(held ? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP, 0, 0, 0, UIntPtr.Zero); break; case TabletOptionButton.ButtonAction.RightClick: mouse_event(held ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP, 0, 0, 0, UIntPtr.Zero); break; case TabletOptionButton.ButtonAction.ScrollDown: if (held) { mouse_event(MOUSEEVENTF_WHEEL, 0, 0, -120, UIntPtr.Zero); } break; case TabletOptionButton.ButtonAction.ScrollUp: if (held) { mouse_event(MOUSEEVENTF_WHEEL, 0, 0, 120, UIntPtr.Zero); } break; case TabletOptionButton.ButtonAction.ShowOptions: if (held) { _frmOptions.ShowOptions(); } break; case TabletOptionButton.ButtonAction.TurnOffTablet: if (conn.Receiver != null && held) { conn.Receiver.TurnOffDevice(conn.ReceiverIndex); } break; case TabletOptionButton.ButtonAction.SwitchTabletDisplay: if (held) { //Find our current display in the AllScreens list, and then switch to the next one int?index = null; for (int i = 0; i < Screen.AllScreens.Length; i++) { if (conn.CurrentDisplay == Screen.AllScreens[i]) { index = i; break; } } if (!index.HasValue) { conn.CurrentDisplay = Screen.PrimaryScreen; } else { conn.CurrentDisplay = Screen.AllScreens[(index.Value + 1) % Screen.AllScreens.Length]; } } break; case TabletOptionButton.ButtonAction.ExecuteFile: if (held) { try { bool ignore = false; var p = new Process(); p.StartInfo.ErrorDialog = true; switch (button) { case TabletOptionButton.TabletButton.ACross: p.StartInfo.FileName = conn.Settings.AFile; break; case TabletOptionButton.TabletButton.BCircle: p.StartInfo.FileName = conn.Settings.BFile; break; case TabletOptionButton.TabletButton.XSquare: p.StartInfo.FileName = conn.Settings.XFile; break; case TabletOptionButton.TabletButton.YTriangle: p.StartInfo.FileName = conn.Settings.YFile; break; case TabletOptionButton.TabletButton.Up: p.StartInfo.FileName = conn.Settings.UpFile; break; case TabletOptionButton.TabletButton.Down: p.StartInfo.FileName = conn.Settings.DownFile; break; case TabletOptionButton.TabletButton.Left: p.StartInfo.FileName = conn.Settings.LeftFile; break; case TabletOptionButton.TabletButton.Right: p.StartInfo.FileName = conn.Settings.RightFile; break; case TabletOptionButton.TabletButton.Start: p.StartInfo.FileName = conn.Settings.StartFile; break; case TabletOptionButton.TabletButton.BackSelect: p.StartInfo.FileName = conn.Settings.BackFile; break; case TabletOptionButton.TabletButton.PSXboxGuide: p.StartInfo.FileName = conn.Settings.GuideFile; break; case TabletOptionButton.TabletButton.PenClick: p.StartInfo.FileName = conn.Settings.ClickFile; break; default: ignore = true; break; } if (!ignore) { p.Start(); } } catch { //Whatever... } } break; default: break; } }