传智播客C/C++:尹成C基础
Day3
1.控制鼠标键盘
//注意关闭360安全卫士,否则会拦截
#include <stdio.h>
#include <stdlib.h>
#inlcude <windows.h>//调用系统函数库
/*控制键盘实现输入组合键*/
/*WIN+R*/
keybd_event(VK_RWIN,0,0,0);//win键按下
keybd_event('R',0,0,0);//R键按下
Sleep(20);//模拟键盘延迟
keybd_event('R',0,KEYEVENTF_KEYUP,0);//R键抬起
keybd_event(VK_RWIN,0,2,0);//win键抬起
1.1Keyevent()函数实现控制键盘
VOID keybd_event(
BYTE bVk, // virtual-key code
BYTE bScan, // hardware scan code
DWORD dwFlags, // flags specifying various function options
DWORD dwExtraInfo // additional data associated with keystroke
);
//键值表:https://msdn.microsoft.com/en-us/library/dd375731(v=vs.85).aspx
1.1.1模拟WIN+R并打开NOTEPAD
int main()
{
//模拟WIN+R 并且打开notepad
keybd_event(VK_RWIN, 0, 0, 0);
keybd_event('R', 0, 0, 0);
Sleep(200);
keybd_event('R', 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_RWIN, 0, KEYEVENTF_KEYUP, 0);
//输入notepad
Sleep(500);
keybd_event('N', 0, 0, 0);//键盘输入,哪有大小写字母的区别
Sleep(20);
keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
keybd_event('O', 0, 0, 0);//键盘输入,哪有大小写字母的区别
Sleep(20);
keybd_event('O', 0, KEYEVENTF_KEYUP, 0);
keybd_event('T', 0, 0, 0);//键盘输入,哪有大小写字母的区别
Sleep(20);
keybd_event('T', 0, KEYEVENTF_KEYUP, 0);
keybd_event('E', 0, 0, 0);//键盘输入,哪有大小写字母的区别
Sleep(20);
keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
keybd_event('P', 0, 0, 0);//键盘输入,哪有大小写字母的区别
Sleep(20);
keybd_event('P', 0, KEYEVENTF_KEYUP, 0);
keybd_event('A', 0, 0, 0);//键盘输入,哪有大小写字母的区别
Sleep(20);
keybd_event('A', 0, KEYEVENTF_KEYUP, 0);
keybd_event('D', 0, 0, 0);//键盘输入,哪有大小写字母的区别
Sleep(20);
keybd_event('D', 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_RETURN, 0, 0, 0);
Sleep(200);
keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
}
1.2Mouseevent()函数实现控制鼠标
void main3()
{
//鼠标模拟
//WIN+D回到桌面
Sleep(200);
keybd_event(0x5b, 0, 0, 0);
keybd_event('D', 0, 0, 0);
Sleep(200);
keybd_event('D', 0, 2, 0);
keybd_event(0x5b, 0, 2, 0);
Sleep(200);
SetCursorPos(40, 40);//设置焦点
//实现双击
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
system("pause");
}
2.OllyDby窗口工具
利用这个插件,可以获得活动窗口的句柄,但是这个插件我没找到。原本以为是获取了窗口的句柄之后,可以利用程序模拟鼠标键盘对其操作,但是老师并没有讲。
3.常量与变量
3.1定义常量的两种方式
#define name "yincheng"
#define age 10
const char str[30] = "yincheng";
const int age = 30;
3.2不用新的变量实现x,y值的互换(节约内存)
int x = 15;
int y = 20;
x = x+y;
y = x-y;
x = x-y;
3.3变量的数据类型
3.3.1进制转换
二进制转换成八进制:
001 101 010 100 110 010
1 5 2 4 6 2
二进制转换成十六进制:
0001 1010 0010 1101
1 A 2 D
二进制与十进制小数互转:
(0.1)2=2^-1=0.5
(0.5)10=2 * 0.5=1->0.1
十进制转换成二进制:乘2取整
0.752=1.5->1;
0.52=1->1;
(0.75)10=>(0.11)2
3.3.2数据类型的作用
sizeof不是函数而是运算符,所以不需要调用任何头文件。
3.3.3符号的意义
#include <stdio.h>
#include <limits.h>
void main()
{
signed int num = INT_MAX;//limits.h里定义了原型
unsigned int unum = UINT_MAX;
printf("%d,%d", sizeof(signed int), sizeof(unsigned int));
printf("\n%ld,%ud\n", num, unum); //注意这里ud是无符号整数
system("pause");
}
3.3.4写DLL模块,用DllInject注入进程
/*打开百度,自动搜索JAVA点广告*/
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <shellapi.h>
void openbaidu()
{
ShellExecuteA(NULL, "open", "http://www.baidu.com", NULL,NULL,SW_NORMAL);
//system("调用IE"),但是这样是同步打开,必须关闭之后才执行后面的
}
void search_java()
{
keybd_event('J', 0, 0, 0);
keybd_event('J', 0, KEYEVENTF_KEYUP, 0);
keybd_event('A', 0, 0, 0);
keybd_event('A', 0, KEYEVENTF_KEYUP, 0);
keybd_event('V', 0, 0, 0);
keybd_event('V', 0, KEYEVENTF_KEYUP, 0);
keybd_event('A', 0, 0, 0);
keybd_event('A', 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_RETURN, 0, 0, 0);
keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
}
void click_AD()
{
Sleep(200);
SetCursorPos(421, 230);
Sleep(200);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Sleep(300);//注意这里的等待时间
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
_declspec(dllexport) void run()
{
openbaidu();
Sleep(3000);
search_java();
click_AD();
//system("pause");
}
3.3.5MssageBoxA()函数
#include<stdio.h>
#include<windows.h>
void main()
{
MessageBoxA(0, "第一个C窗体程序", "消息", 3);
//参数1:系统弹出
// 参数2:消息内容
// 参数3:标题
// 参数4:对话框的类型
// 0 只有 确定 按钮;
// 1 确定 取消 按钮;
// 2 终止 重试 忽略 按钮
// 3 是 否 取消 按钮
getchar();
}
3.3.6ShellExcuteA()函数
#include<windows.h>
void main()
{
// _In_opt_ HWND hwnd, //系统启动
//_In_opt_ LPCSTR lpOperation,//open打开
//_In_ LPCSTR lpFile,//指令
//_In_opt_ LPCSTR lpParameters,//默认0
//_In_opt_ LPCSTR lpDirectory,//默认0
//_In_ INT nShowCmd//0隐藏 3最大化 6最小化 其余正常
ShellExecuteA(0, "open", "notepad", 0, 0, 3);//最大化打开记事本
ShellExecuteA(0, "open", "tasklist", 0, 0, 1);//执行tasklist命令
ShellExecuteA(0, "open", "www.baidu.com", 0, 0, 3);//打开百度网站
ShellExecuteA(0, "open", "C:\\Users\\Administrator\\Desktop\\笔记2.txt", 0, 0, 3);//打开txt文件
ShellExecuteA(0, "print", "C:\\Users\\Administrator\\Desktop\\翻译.docx", 0, 0, 0);//调用打印机打印
}
网友评论