Created
July 18, 2016 16:23
-
-
Save kkm/4f12b3e734af548815587c098ad6c2ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var colors = require("D:\\kkm\\Desktop\\node_modules\\colors"); | |
var robot = require("C:\\Users\\kkm\\node_modules\\robot-js"); | |
var mouse = robot.Mouse(); | |
var keyboard = robot.Keyboard(); | |
mouse.autoDelay.min = 1; | |
mouse.autoDelay.max = 1; | |
var img = robot.Image(); | |
var targetColor = [0xF2361B, 0xEF3519, 0xEE4131, 0xED4233, 0xEE4031, 0xCF8790, 0xCF878F, 0xD92411, 0xDC2613, 0xA24D53, 0xA84547, 0xB25C62, 0xAB545B]; | |
var pixelColor = robot.Color(); | |
var i = 0; | |
var k = 0; | |
var data, | |
r2, | |
g2, | |
b2, | |
r1, | |
g1, | |
b1, | |
s; | |
if (robot.Screen.synchronize()) { | |
robot.Screen.setCompositing(false); | |
robot.Screen.grabScreen(img); | |
} | |
var w = img.getWidth() / 2; | |
var h = img.getHeight() / 2; | |
var searchSize = .97; | |
var step = 3; | |
console.log(("Init 0.1 TriggerBot").cyan); | |
console.log("Monitor Width: " + img.getWidth() + " " + "Height: " + img.getHeight() + " " + "Center is: " + w + ", " + h); | |
//console.log("Only single monitor is supported. Please run CMD as administrator (prevents Overwatch from seeing CMD's actions). Change SearchSize and Step to your liking, SearchSize should be between .90 and .99, the bigger SearchSize is, the smaller the search box. Step is how many pixels to skip, will result in a faster scan but slower response. Center is: " + w + ", " + h); | |
while (1) { | |
s = robot.Mouse.getState(); | |
if (s[robot.BUTTON_MIDDLE]) | |
bang(); | |
} | |
function bang() { | |
robot.Screen.grabScreen(img, Math.round(searchSize * w), Math.round(searchSize * h), Math.round((1 - searchSize) * w), Math.round((1 - searchSize) * h)); | |
data = img.getData(); | |
//copy dann paste in mspaint | |
//robot.Clipboard.setImage(img); | |
//console.log("img length:" + img.getLength()); | |
for ( i = 0; i < img.getLength(); i += step) { | |
if (similar((data[i] & 0x00FFFFFF).toString(16).toUpperCase(), 15)) { | |
//console.log(data[i]); | |
//console.log(data[i] & 0x00FFFFFF); | |
//console.log((data[i] & 0x00FFFFFF).toString(16).toUpperCase()); | |
//Tastatur N drücken | |
//keyboard.click(robot.KEY_N); | |
var mouse = robot.Mouse(); | |
mouse.click(robot.BUTTON_RIGHT); | |
return; | |
} | |
} | |
return; | |
} | |
function similar(aneighbor, atolerance) { | |
if (atolerance == undefined) { | |
atolerance = 10; | |
} | |
r2 = parseInt(aneighbor.substr(0, 2), 16); | |
g2 = parseInt(aneighbor.substr(2, 2), 16); | |
b2 = parseInt(aneighbor.substr(4, 2), 16); | |
for ( k = 0; k < targetColor.length; k++) { | |
r1 = parseInt(targetColor[k].toString(16).toUpperCase().substr(0, 2), 16); | |
g1 = parseInt(targetColor[k].toString(16).toUpperCase().substr(2, 2), 16); | |
b1 = parseInt(targetColor[k].toString(16).toUpperCase().substr(4, 2), 16); | |
if (Math.abs(r1 - r2) <= atolerance && Math.abs(g1 - g2) <= atolerance && Math.abs(b1 - b2) <= atolerance) { | |
//console.log(r2 + " " + b2 + " " + g2 + " " + r1 + " " + b1 + " " + g1); | |
return true; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment