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 ...
随机推荐
- 关于Aop切面中的@Before @Around等操作顺序的说明
[转]http://www.cnblogs.com/softidea/p/6123307.html 话不多说,直接上代码: package com.cdms.aop.aspectImpl; impor ...
- 攻防常用命令(linux)
1.修改SSH密码: #登录SSH passwd 出现current passwoed或new password 输入就密码再输入新密码确认或直接输入新密码确认即可 2.修改Mysql密码: 1.在m ...
- cucumber学习笔记
来源于cucumber官网 学习完了之后全部整理一遍
- Java基础--二维数组
1.二维数组的定义 二维数组表示行列二维结构,在栈空间中的二维数组的地址指向堆空间中的一维数组,堆空间中的一维数组的地址又指向一维数组所在的内存空间. 2.二维数组的声明 二维数组声明有3种方式,推荐 ...
- 模仿OpenStack写自己的RPC
在openstack中使用两种通信方式,一种是Restful API,另一种是远程过程调用RPC.本片文章主要讲解openstack中RPC的使用方式,以及如何在我们自己的架构中使用RPC. 在我前面 ...
- gantt project 使用
市场上有不少项目计划类系统, 很多都是收费的, 还有很多都是web版, 这些都自然被排除了. 免费好用的还真不多, 今天简单介绍一下 gantt project 这个软件, 开源并且免费, 基于 ja ...
- java下载远程文件到本地
java下载远程文件到本地(转载:http://www.cnblogs.com/qqzy168/archive/2013/02/28/2936698.html) /** * 下载远程文 ...
- LOJ #6509. 「雅礼集训 2018 Day7」C
神仙题 LOJ #6509 题意 给定一棵树,点权为0/1,每次随机一个点(可能和之前所在点相同)走到该点并将其点权异或上1 求期望的移动距离使得所有点点权相同 题解 根本不会解方程 容易发现如果一个 ...
- css3混合模式
https://juejin.im/entry/5b4802d15188251ac446d3a9
- sql注入--双查询报错注入原理探索
目录 双查询报错注入原理探索 part 1 场景复现 part 2 形成原因 part 3 报错原理 part 4 探索小结 双查询报错注入原理探索 上一篇讲了双查询报错查询注入,后又参考了一些博客, ...