傳智播客C/C++:尹成C基礎(chǔ)
Day3
1.控制鼠標(biāo)鍵盤
//注意關(guān)閉360安全衛(wèi)士植阴,否則會攔截
#include <stdio.h>
#include <stdlib.h>
#inlcude <windows.h>//調(diào)用系統(tǒng)函數(shù)庫
/*控制鍵盤實現(xiàn)輸入組合鍵*/
/*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()函數(shù)實現(xiàn)控制鍵盤
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);//鍵盤輸入访敌,哪有大小寫字母的區(qū)別
Sleep(20);
keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
keybd_event('O', 0, 0, 0);//鍵盤輸入法瑟,哪有大小寫字母的區(qū)別
Sleep(20);
keybd_event('O', 0, KEYEVENTF_KEYUP, 0);
keybd_event('T', 0, 0, 0);//鍵盤輸入,哪有大小寫字母的區(qū)別
Sleep(20);
keybd_event('T', 0, KEYEVENTF_KEYUP, 0);
keybd_event('E', 0, 0, 0);//鍵盤輸入责循,哪有大小寫字母的區(qū)別
Sleep(20);
keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
keybd_event('P', 0, 0, 0);//鍵盤輸入,哪有大小寫字母的區(qū)別
Sleep(20);
keybd_event('P', 0, KEYEVENTF_KEYUP, 0);
keybd_event('A', 0, 0, 0);//鍵盤輸入寂玲,哪有大小寫字母的區(qū)別
Sleep(20);
keybd_event('A', 0, KEYEVENTF_KEYUP, 0);
keybd_event('D', 0, 0, 0);//鍵盤輸入殷绍,哪有大小寫字母的區(qū)別
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()函數(shù)實現(xiàn)控制鼠標(biāo)
void main3()
{
//鼠標(biāo)模擬
//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);//設(shè)置焦點
//實現(xiàn)雙擊
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窗口工具
利用這個插件,可以獲得活動窗口的句柄桐经,但是這個插件我沒找到毁兆。原本以為是獲取了窗口的句柄之后,可以利用程序模擬鼠標(biāo)鍵盤對其操作阴挣,但是老師并沒有講气堕。
3.常量與變量
3.1定義常量的兩種方式
#define name "yincheng"
#define age 10
const char str[30] = "yincheng";
const int age = 30;
3.2不用新的變量實現(xiàn)x,y值的互換(節(jié)約內(nèi)存)
int x = 15;
int y = 20;
x = x+y;
y = x-y;
x = x-y;
3.3變量的數(shù)據(jù)類型
3.3.1進(jìn)制轉(zhuǎn)換
二進(jìn)制轉(zhuǎn)換成八進(jìn)制:
001 101 010 100 110 010
1 5 2 4 6 2
二進(jìn)制轉(zhuǎn)換成十六進(jìn)制:
0001 1010 0010 1101
1 A 2 D
二進(jìn)制與十進(jìn)制小數(shù)互轉(zhuǎn):
(0.1)2=2^-1=0.5
(0.5)10=2 * 0.5=1->0.1
十進(jìn)制轉(zhuǎn)換成二進(jìn)制:乘2取整
0.752=1.5->1;
0.52=1->1;
(0.75)10=>(0.11)2
3.3.2數(shù)據(jù)類型的作用
sizeof不是函數(shù)而是運算符,所以不需要調(diào)用任何頭文件畔咧。
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是無符號整數(shù)
system("pause");
}
3.3.4寫DLL模塊茎芭,用DllInject注入進(jìn)程
/*打開百度,自動搜索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("調(diào)用IE"),但是這樣是同步打開誓沸,必須關(guān)閉之后才執(zhí)行后面的
}
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()函數(shù)
#include<stdio.h>
#include<windows.h>
void main()
{
MessageBoxA(0, "第一個C窗體程序", "消息", 3);
//參數(shù)1:系統(tǒng)彈出
// 參數(shù)2:消息內(nèi)容
// 參數(shù)3:標(biāo)題
// 參數(shù)4:對話框的類型
// 0 只有 確定 按鈕梅桩;
// 1 確定 取消 按鈕;
// 2 終止 重試 忽略 按鈕
// 3 是 否 取消 按鈕
getchar();
}
3.3.6ShellExcuteA()函數(shù)
#include<windows.h>
void main()
{
// _In_opt_ HWND hwnd, //系統(tǒng)啟動
//_In_opt_ LPCSTR lpOperation,//open打開
//_In_ LPCSTR lpFile,//指令
//_In_opt_ LPCSTR lpParameters,//默認(rèn)0
//_In_opt_ LPCSTR lpDirectory,//默認(rèn)0
//_In_ INT nShowCmd//0隱藏 3最大化 6最小化 其余正常
ShellExecuteA(0, "open", "notepad", 0, 0, 3);//最大化打開記事本
ShellExecuteA(0, "open", "tasklist", 0, 0, 1);//執(zhí)行tasklist命令
ShellExecuteA(0, "open", "www.baidu.com", 0, 0, 3);//打開百度網(wǎng)站
ShellExecuteA(0, "open", "C:\\Users\\Administrator\\Desktop\\筆記2.txt", 0, 0, 3);//打開txt文件
ShellExecuteA(0, "print", "C:\\Users\\Administrator\\Desktop\\翻譯.docx", 0, 0, 0);//調(diào)用打印機打印
}