VS挂机移动鼠标代码
#include <time.h>
#include <stdio.h>
#include <Windows.h> HANDLE ghMutex; ///////////////////////////////////////////////////////////////////////////////////
/* 移动鼠标的位置(相对)
* the amount of motion since the last mouse event was generated
* @dx : relative x coordinate is specified as the number of pixels moved
* @dy : relative y coordinate is specified as the number of pixels moved
*/
int MoveMouse(LONG dx, LONG dy)
{
UINT ret;
INPUT input = { }; input.type = INPUT_MOUSE;
input.mi.time = ;//the system will provide time stamp
input.mi.dwFlags = MOUSEEVENTF_MOVE; //Movement occurred.
input.mi.dx = dx;
input.mi.dy = dy; //send Mouse Event
ret = SendInput(, &input, sizeof(INPUT));
if (ret != ) {
printf("SendInput failed, %ld\n", GetLastError());
return -;
} //Assumes the mouse sampling rate is 8ms
Sleep(); return ;
}
//////////////////////////////////////////////////////////////////////////////////////
enum MouseButtonType {
BUTTON_LEFT, //鼠标左键
BUTTON_RIGHT, //鼠标右键
BUTTON_MID //鼠标中键(滚轮)
}; enum MouseClickType {
BUTTON_PRESS, //按键压下
BUTTON_RELEASE, //按键抬起
BUTTON_CLICK //按键点击(压下后抬起)
}; int ClickMouse(MouseButtonType ButtonType, MouseClickType ClickType)
{
UINT ret;
UINT count = ;
INPUT input[] = { }; struct MouseOperArr {
MouseButtonType button;
struct MouseEvtFlg {
UINT flgCnt;
DWORD dwFlags[];
}flags[];
} MouseEvtArr[] = {
{ BUTTON_LEFT, { { , { MOUSEEVENTF_LEFTDOWN, } }, \
{, { MOUSEEVENTF_LEFTUP, }}, {, { MOUSEEVENTF_LEFTDOWN, MOUSEEVENTF_LEFTUP } } } },
{ BUTTON_RIGHT, { { , { MOUSEEVENTF_RIGHTDOWN, } }, \
{, { MOUSEEVENTF_RIGHTUP, }}, { , { MOUSEEVENTF_RIGHTDOWN, MOUSEEVENTF_RIGHTUP } } } },
{ BUTTON_MID, { { , { MOUSEEVENTF_MIDDLEDOWN, } }, \
{, { MOUSEEVENTF_MIDDLEUP, }}, { ,{ MOUSEEVENTF_MIDDLEDOWN, MOUSEEVENTF_MIDDLEUP } } } }
}; //common data
input[].type = INPUT_MOUSE;
input[].mi.time = ;//the system will provide time stamp
input[].type = INPUT_MOUSE;
input[].mi.time = ;//the system will provide time stamp count = MouseEvtArr[ButtonType].flags[ClickType].flgCnt;
input[].mi.dwFlags = MouseEvtArr[ButtonType].flags[ClickType].dwFlags[];
input[].mi.dwFlags = MouseEvtArr[ButtonType].flags[ClickType].dwFlags[]; //send Mouse Event
ret = SendInput(count, input, sizeof(INPUT));
if (ret != count) {
printf("SendInput failed, %ld\n", GetLastError());
return -;
} //Assumes the mouse sampling rate is 8ms
Sleep(); return ;
} #define HK_ALT_F1 (1001)
#define HK_ALT_F2 (1002)
#define HK_ALT_F3 (1003) DWORD WINAPI ThreadEntry(LPVOID lpThreadParameter)
{
srand(time(NULL)); while () {
//wait for message to startup
WaitForSingleObject(ghMutex, INFINITE); //压下左键不松手
// ClickMouse(BUTTON_LEFT, BUTTON_PRESS); int number = rand() % ;
int dir = (number > ? : -);
printf("Move\n");
MoveMouse(dir * number, dir * number); //release mutex for new message
ReleaseMutex(ghMutex);
Sleep();
} return ;
} int main(void)
{
//注册热键 Alt + F1,用于启动程序
RegisterHotKey(NULL, HK_ALT_F1, MOD_ALT | MOD_NOREPEAT, VK_F1);
//注册热键 Alt + F2,用于暂停程序
RegisterHotKey(NULL, HK_ALT_F2, MOD_ALT | MOD_NOREPEAT, VK_F2);
//注册热键 Alt + F2,用于退出程序
RegisterHotKey(NULL, HK_ALT_F3, MOD_ALT | MOD_NOREPEAT, VK_F3); ghMutex = CreateMutex(NULL, FALSE, NULL);
WaitForSingleObject(ghMutex, INFINITE); //创建工作线程
HANDLE handle = CreateThread(NULL, , ThreadEntry, NULL, , NULL); //主线程 用于接收热键消息
MSG msg = { };
while (GetMessage(&msg, NULL, , )) {
switch (msg.message) {
case WM_HOTKEY:
switch (msg.wParam) {
case HK_ALT_F1://接收到ALT + F1
ReleaseMutex(ghMutex);
break;
case HK_ALT_F2://接收到ALT + F2
WaitForSingleObject(ghMutex, INFINITE);
break;
case HK_ALT_F3:
goto FINISH;
break;
default:
break;
}
break;
case WM_QUIT:
case WM_CLOSE:
goto FINISH;
break;
default:
break; }
}
FINISH:
CloseHandle(ghMutex);
UnregisterHotKey(NULL, HK_ALT_F1);
UnregisterHotKey(NULL, HK_ALT_F2);
UnregisterHotKey(NULL, HK_ALT_F3); //close worker thread
TerminateThread(handle, );
WaitForSingleObject(handle, INFINITE);
CloseHandle(handle); return ;
}
VS挂机移动鼠标代码的更多相关文章
- Listbox与dataGridView的获取鼠标点击事件的区别!!!
lisxian.SelectedIndex = index; Listbox获取鼠标的代码!!!! DataGridViewRow currenRow = this.dgvxian3.Rows[ind ...
- c# WinForm英雄联盟挂机源码及实现原理
主要功能:全自动化英雄联盟挂机,游戏中会在原地放技能保持不掉线状态,游戏结束自动重新开始,自动选择英雄,可以晚上挂机刷人机: 缺陷:没怎么完善,如果掉线或者游戏崩溃网络断了软件会自动停止操作,使用时间 ...
- winform界面特效470多例
一共470多例winform 界面特效的源码. 实例030 窗口颜色的渐变 实例说明 在程序设计时,可以通过设置窗体的BackColor属性来改变窗口的背景颜色.但是这个属性改变后整个窗体的客户区都会 ...
- C#实例.net_经典例子400个
一共470多例winform 界面特效的源码. 窗体与界面设计... 9 实例001 带历史信息的菜单 10 实例002 菜单动态合并 12 实例003 像开始菜单一样漂亮的菜单.. ...
- PHPstorm 的快捷键
// ctrl+shift+n 查找文件// ctrl+j 插入活动代码提示// ctrl+alt+t 当前位置插入环绕代码// alt+insert ...
- STM32实现HID和u盘复合设备
USB设备可以定义一个复合设备,复合设备分两种,一种是一个设备多个配置,还有一种是一个配置多个接口,在本例中采用一个配置多个接口的方式 首先修改设备描述符,标准设备描述符和报告描述符都不需要修改, ...
- USB自定义HID设备实现-LPC1768
首先在之前鼠标的基础上修改设备描述符 #include "usbdesc.h" //usb标准设备描述符 const U8 USB_DeviceDescriptor[] = { U ...
- USB自定义HID设备实现-STM32
该文档使用USB固件库,在其基础上进行了自己的定制,完成了一个USB-HID设备,首先是usb_desc.c文件,里面存放了usb各种描述符的存在 #include "usb_desc.h& ...
- lpc1768usb端点响应以及描述符定义
#ifndef __USBEP1_H_ #define __USBEP1_H_ #include "usb.h" #include "usbhw.h" exte ...
随机推荐
- Spring MVC通过AOP切面编程 来拦截controller 实现日志的写入
首选需要参考的是:[参考]http://www.cnblogs.com/guokai870510826/p/5977948.html http://www.cnblogs.com/guokai8 ...
- 公共DNS推荐及dns测速
DNS在平时上网中扮演重要角色,如果不注意DNS的话,可能会导致网速慢.弹窗广告.网址打不开.打开不是自己想要的网站.劫持等一系列问题.针对DNS的问题,今天我们就来总结一下,看看哪个DNS服务器最好 ...
- showdoc app接口文档编写利器
通过朋友介绍,才知道有这么好的一个在线接口编写文档开源项目,非常感谢原作者的贡献 ShowDoc介绍 关于ShowDoc的介绍,请访问:http://blog.star7th.com/2015/11/ ...
- 基于Redis的分布式锁真的安全吗?
说明: 我前段时间写了一篇用consul实现分布式锁,感觉理解的也不是很好,直到我看到了这2篇写分布式锁的讨论,真的是很佩服作者严谨的态度, 把这种分布式锁研究的这么透彻,作者这种技术态度真的值得我好 ...
- LeetCode-11. 盛最多水的容器
给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线, ...
- idea 错误: 找不到或无法加载主类
1.cmd进入项目目录 2.输入maven命令重构项目 mvn clean mvn idea:idea install
- centos7安装与配置nginx1.11,开机启动
1.官网下载安装包 http://nginx.org/en/download.html,选择适合Linux的版本,这里选择最新的版本,下载到本地后上传到服务器或者centos下直接wget命令下载. ...
- 开放源代码的设计层面框架Spring——day04
spring第四天 一.Spirng中的JdbcTemplate 1.1JbdcTemplate概述 他是spring框架中提供的一个对象,是对原始Jd ...
- C# 类型转换的开销
先来个测试: static void Main(string[] args) { Stopwatch stopwatch; string strStr = "string"; ob ...
- Hexo博客部署-使用github作为保存中转仓库
本篇是在VPS上搭建Hexo静态博客的第一篇博文,写本篇的目的一是纪念一下,二是作为一个部署文档保留. 博客地址 相关描述 VPS环境是在搬瓦工上安装的centos6(x86),1核,512MB,10 ...