/// <summary> /// 表示一个按键动作 (一直按左键,一直按w键) /// </summary> /// <param name="hotkeyModifierKeys">标识按键 如 Ctrl Shift,支持 ModifierKeys.Ctrl | ModifierKeys.Shift</param> /// <param name="hotkeyNormalKeys">普通键盘按键,如 C</param> /// <param name="window">传入this即可</param> /// <param name="describe">对这次按键动作的文本描述</param> /// <param name="pressedKey">按下热键后 要一直按住的键盘键值</param> /// <param name="pressedMouse">按下热键后 要一直按住的鼠标键值</param> public KeyAction(ModifierKeys hotkeyModifierKeys, WF.Keys hotkeyNormalKeys, Window window, string describe, List <Key> pressedKey, List <MouseButton> pressedMouse) { hotKey = new HotKey(hotkeyModifierKeys, hotkeyNormalKeys, window); hotKey.HotKeyPressed += HotKey_HotKeyPressed; Describe = describe; if (pressedKey == null) { pressedKey = new List <Key>(); } if (pressedMouse == null) { pressedMouse = new List <MouseButton>(); } PressedKey = pressedKey; PressedMouse = pressedMouse; foreach (var key in PressedKey) { KeyboardSimulation.Reset(); timer.Tag = key; } foreach (var mouse in PressedMouse) { MouseSimulation.Down(mouse); } timer.Tick += Timer_Tick; }
private void SimulInput() { int x = Cursor.Position.X; int y = Cursor.Position.Y; //MouseSimulation.MouseUp(MouseEventType.NONE, 10, 10); //Thread.Sleep(100); //MouseSimulation.MouseUp(MouseEventType.NONE, x, y); //Debug.WriteLine("{0} SimulInput {1}, {2}", DateTime.Now.ToString("HHmmss"), x, y); bool isRemote = WinAPI.GetSystemMetrics(SystemMetric.SM_REMOTESESSION) != 0; //Debug.WriteLine("{0} isRemote: {1}", DateTime.Now.ToString("HHmmss"), isRemote); if (WindowControl.GetTopWindowProcess() == null) { // TimeKeeper 근무시작 버튼 위치 MouseSimulation.MouseClick(MouseEventType.LEFT, 80, 45); } else if (isRemote) { // control key KeyboardSimulation.MakeKeyEvent(0x11, KeyboardEventType.KEYDOWN); KeyboardSimulation.MakeKeyEvent(0x11, KeyboardEventType.KEYUP); } else { drawStar.Draw(); } }
private void HotKey_HotKeyPressed(HotKey obj) { if (timer.IsEnabled) { KeyboardSimulation.Reset(); foreach (var key in PressedMouse) { MouseSimulation.Up(key); } } timer.IsEnabled = !timer.IsEnabled; }
/// <summary> /// 长截图函数,合并图像部分还有待完善 /// </summary> /// <param name="selectRect"></param> /// <returns></returns> private Bitmap captureLongBitmap(Rectangle selectRect) { List <Bitmap> bitmaps = new List <Bitmap>(); int dwData = (int)(0.9 * selectRect.Height); Bitmap bitmap = captureBitmap(selectRect); bitmaps.Add(bitmap); Double distance = 0; int wheelPointX = selectRect.X + selectRect.Width / 2; int wheelPointY = selectRect.Y + selectRect.Height / 2; while (true) { MouseSimulation.MoveMouseWHEEL(wheelPointX, wheelPointY, -dwData); System.Threading.Thread.Sleep(DELAY_TIME); bitmap = captureBitmap(selectRect); distance = ImageTool.Calculate_Distance(bitmap, bitmaps[bitmaps.Count - 1]); if (distance < 0.4) { //bitmaps.Add(bitmap); Console.WriteLine("滚动结束," + distance.ToString()); break; } else { bitmaps.Add(bitmap); Console.WriteLine("滚动图片" + bitmaps.Count.ToString() + "," + distance.ToString()); } } int i = 0; foreach (Bitmap b in bitmaps) { string filename = "roll/" + i++.ToString() + ".png"; b.Save(filename, ImageFormat.Png); } Bitmap longBitmap = generateLongBitmap(bitmaps, selectRect); return(longBitmap); }