I had this idea earlier today, and tried making it, but ran into difficulties with the quickscoping part. The macro would wait until you left click, stop the left click, then right click. It would wait a period of time for the scope to zoom in (I found a table of zooming times on the AVA forums), then left click, and quickswitch (using any method, like q-q, or 1-2, 1-3, etc).
I got the quickswitch code down ez, but the quickscope is difficult, because by the time the program registers the left click, so has the game, and it already shoots.
Here's what I made so far:
Code:
#define WINVER 0x0500
#include <iostream>
#include <windows.h>
#include <winable.h>
using namespace std;
void quick_switch(){
INPUT input;
input.type = INPUT_KEYBOARD;
input.ki.wScan = 0;
input.ki.time = 0;
input.ki.dwExtraInfo = 0;
input.ki.wVk = 0x51; //Virtual keycode for Q, I'm too lazy to add other methods of quickswitching right now
SendInput(1, &input, sizeof(INPUT));
Sleep(10);
input.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &input, sizeof(INPUT));
}
void unclick(bool left_or_right){
INPUT input = {0};
//input.mi.dwExtraInfo = 0x200;
input.type = INPUT_MOUSE;
if(left_or_right){ //if true, it's a left click
input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(1, &input, sizeof(INPUT));
}
else if(!left_or_right){ //false, right click
input.mi.dwFlags = MOUSEEVENTF_RIGHTUP;
SendInput(1, &input, sizeof(INPUT));
}
}
void click(bool left_or_right){
INPUT input = {0};
input.mi.dwExtraInfo = 0x200;
input.type = INPUT_MOUSE;
if(left_or_right){
input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
SendInput(1, &input, sizeof(INPUT));
}
else if(!left_or_right){
input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
SendInput(1, &input, sizeof(INPUT));
}
}
int scope_speed_milliseconds;
LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam) { //hook for mouse wheel
PKBDLLHOOKSTRUCT k = (PKBDLLHOOKSTRUCT)(lParam);
if(wParam == WM_LBUTTONDOWN){
unclick(true); //un_click left
click(false); //click right
unclick(false); //un_click right
Sleep(scope_speed_milliseconds - 20); //wait for the scope to zoom
click(true); //click left
unclick(true); //un_click left
quick_switch(); //quick switch using Q
Sleep(15);
quick_switch(); //switch back to main weapon
}
return CallNextHookEx(0, nCode, wParam, lParam);
}
MSG msg;
int main(){
bool active = true;
float scope_speed_seconds;
//int scope_speed_milliseconds; //commented out to make global for mouse hook
cout << "Scope speeds:" << endl;
cout << "0.12s: Mosin Nagant Basic Scope, AWM Precision Scope" << endl;
cout << "0.14s: FR-F2 Sharpshooter Scope, ASW.338 Quick Scope II, AWM Basic Scope, DSR-1 Quick Scope 2, Blaser R93 Sharpshooter Scope" << endl;
cout << "0.16s: ASW.338 Sharpshooter Scope II" << endl;
cout << "0.18s: ASW.338 Basic Scope" << endl;
cout << "0.20s: M24 Basic Scope, SV98 Precision Scope, FR-F2 Basic Scope, DSR-1 Basic Scope, PGM.338 Precision Scope, Blaser R93 Precison Scope" << endl;
cout << "0.21s: SV98 Basic Scope" << endl;
cout << "0.22s: Blaser R93 Basic Scope, FR-F2 Quick Scope, DSR-1 High Powered Scope 2" << endl;
cout << "0.30s: TPG1 High Powered Scope, PGM.338 High Powered Scope" << endl;
cout << "0.34s: TPG1 Basic Scope, PGM.338 Basic Scope" << endl << endl;
cout << "Enter your scope speed in seconds: ";
cin >> scope_speed_seconds;
scope_speed_milliseconds = scope_speed_seconds * 1000; //Sleep() takes milliseconds
//HHOOK mousehook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProc, NULL, 0);
//SetTimer(NULL, 1, 5, (TIMERPROC) &MouseHookProc); //commented out while not in use
while(true){
while(active){
if((GetKeyState(VK_LBUTTON) & 0x80) != 0){ //if the left mouse button is pressed
unclick(true); //un_click left
click(false); //click right
unclick(false); //un_click right
Sleep(scope_speed_milliseconds - 20); //wait for the scope to zoom
click(true); //click left
unclick(true); //un_click left
quick_switch(); //quick switch using Q
Sleep(15);
quick_switch(); //switch back to main weapon
}
}
//if(GetMessage(&msg, NULL, 0, 0)){
// TranslateMessage(&msg);
// DispatchMessage(&msg);
//}
}
return 0;
}
Simple stuff, catching clicks and sending them. I was trying to make a mouse hook, but it did worse than just using GetKeyState(). I don't do injection hacks, but if someone could inject code into the game to allow this program to grab the left click before the game registers it, this could work. Quickscoping like this may not be very effective, but it's worth a shot.