Pixel search in defined area - autoit

I want to pixel search a defined area. Application is Bluestacks App Player:
Blue rectangle is BlueStacks (its position may change). I get the position using ControlGetPos(). I only want to pixel search in red rectangle inside the app. Position of red rectangle is 307,628,355,675 based on window info with windows coordinate mode. But It's not working. Here's my code :
HotKeySet("{F2}", "mulai")
HotKeySet("{F3}", "berhenti")
Global $lokasi[2]
Global $warna
Global $penghitung
Global $nyala
Global $title = "BlueStacks App Player"
Global $hwnd = WinGetHandle($title)
Global $BSpos
Func berhenti()
Exit
EndFunc ;==>berhenti
Func getPos()
$aPos = ControlGetPos($title, "", "[CLASS:BlueStacksApp; INSTANCE:1]")
$tPoint = DllStructCreate("int X;int Y")
DllStructSetData($tPoint, "X", $aPos[0])
DllStructSetData($tPoint, "Y", $aPos[1])
_WinAPI_ClientToScreen(WinGetHandle(WinGetTitle($title)), $tPoint)
$BSpos[0] = DllStructGetData($tPoint, "X")
$BSpos[1] = DllStructGetData($tPoint, "Y")
EndFunc ;==>getPos
Func mulai()
$nyala = 1
While $nyala = 1
$pos = WinGetPos($hwnd)
WinActivate($hwnd)
$lokasi = PixelSearch($BSpos[0] , $BSpos[1], $BSpos[0] + $BSpos[2], $BSpos[1] + $BSpos[3], 0x0185B3)
MouseMove($lokasi[0], $lokasi[1], 0)
Sleep(200)
If #error Then
$penghitung = $penghitung + 1
EndIf
If $penghitung > 5 Then
$nyala = 0
EndIf
WEnd
EndFunc ;==>mulai
While 1
Sleep(200)
WEnd

It seems there's nothing wrong with the imagesearch library, the problem is I running windows 10 using x64bit. So compiling it using x64 compiler (while it really suggest to use x86 compiler) with administrator previllige solved the problem.

Related

Handle previous state in continuous rotation

Hello i have the following lua code which functionality is to rotate a point creating a circle. The problem I'm having is with initial and/or last state. Since there is a clock running whenever i stop the rotation and start again, the point jumps around. I tried saving the last value after the lfo is turned off, and then use this value in each sin and cos functions but i cannot make it work well.
Thank you!
The Code:
local last = 0
local trigger = false
function update()
t = getMillis()
T = 3000
if trigger == true then
x = math.cos(2*math.pi*( (t - last) + t) /T)
y = math.sin(2*math.pi*( (t - last) + t) /T)
end
end
function onValueChanged(key)
if key == "x" and self.values.x == 1 then
if trigger == true then
last = t
end
trigger = not trigger
end
end

Lua Love2d Quadtree recursion

UPDATE -- I figured it out. Turns out I am bad at math and visualizing 2d points. I wasn't setting south or east subdivisions correctly.
I have been trying to make a quadtree to track points in Love2d. I have the most of the code written, but I don't think the recursion is working properly.
I'm pretty new to the coding scene, so I really don't know where to start.
It seems to leave out points that go into the southeast quadrant.
I think as it goes recursively into the insert function it either looks at the parents point array or doesn't seem to go into all the insert functions.
local QuadTree = {}
QuadTree.__index = QuadTree
function QuadTree:new(boundary,capacity)
local quadTemp = {}
setmetatable(quadTemp, QuadTree)
if (not boundary) then
print('No boundary given to new QuadTree')
end
if (type(capacity) ~= 'number') then
print('Boundary should be a number')
end
if (capacity < 1) then
print('capacity should be greater than one')
end
quadTemp.boundary = boundary
quadTemp.capacity = capacity
quadTemp.points = {}
quadTemp.hasDivided = false
return quadTemp
end
function QuadTree:insert(p)
--If this point doesnt belong in this spot dont add it
if (not self.boundary:contains(p)) then
return false
elseif (#self.points<self.capacity) then
table.insert(self.points,p)
return true
elseif(not self.hasDivided) then
self:subdivide()
elseif(self.hasDivided) then
return self.northeast:insert(p) or
self.northwest:insert(p) or
self.southeast:insert(p) or
self.southwest:insert(p)
end
end
function QuadTree:subdivide()
local x = self.boundary.xpos
local y = self.boundary.ypos
local w = self.boundary.width / 2
local h = self.boundary.height / 2
local nw = Rectangle:new(x,y,w,h)
self.northwest = QuadTree:new(nw,self.capacity)
local ne = Rectangle:new(w,y,w,h)
self.northeast = QuadTree:new(ne,self.capacity)
local sw = Rectangle:new(x,h,w,h)
self.southwest = QuadTree:new(sw,self.capacity)
local se = Rectangle:new(w,h,w,h)
self.southeast = QuadTree:new(se,self.capacity)
self.hasDivided = true
end
function QuadTree:query(range,found)
--If we havent found any yet lets create a list incase we do
if (not found) then found = {} end
--If this cell doesnt contain the boundary then return an empty list
if (not range:intersects(self.boundary)) then
return found
end
for k,v in pairs(self.points) do
if (range:contains(v)) then
table.insert(found,v)
end
end
--If the current cell has divided we need to check its children
if (self.hasDivided) then
self.northwest:query(range,found)
self.northeast:query(range,found)
self.southwest:query(range,found)
self.southeast:query(range,found)
end
return found;
end

Pyqt bind function to dinamically generated push buttons

Using the PyQT library I am currently having issues with binding a function to the dinamically generated pushbuttons resulting from a loop.
So far I have managed to generate the buttons and bind a function to them with the lambda command. The problem is that since I need every single button to open a different file I find myself in an odd situation as all the button do open the same one. The last value assigned to the variable.
Any idea on how to fix the situation? As a last note, sorry in case of stupid mistakes. I am new to OOP and PyQT.
def searchTheStuff(self):
found = 0
data = MainWindow.intermediateCall()
f1 = open('Path.txt', 'r')
path = f1.read()
f1.close()
Yinc = 25
Y = 40
X = 20
results = 0
for path, dirs, files in os.walk(path, topdown=True):
for name in files:
if name.endswith('.txt'):
fullpath = os.path.join(path, name)
mail = open_close(fullpath)
if mail.find(data) != -1 and results<3:
found = 1
self.buttons.append(QtGui.QPushButton(self))
print fullpath
command = lambda : webbrowser.open()
self.buttons[-1].clicked.connect(command)
self.buttons[-1].setText(_translate("self", name, None))
self.buttons[-1].setGeometry(QtCore.QRect(X, Y, 220, 20))
results = results+1
if results == 33:
X = 260
Y = 15
Y = Y + Yinc
if found == 0:
self.label = QtGui.QLabel(self)
self.label.setGeometry(QtCore.QRect(20, 40, 321, 21))
self.label.setText(_translate("self", "No templates have been found:", None))

LUA. io.read with time limit

it is possible set time limit to read input in terminal in Lua.
For example you habe only 1 second to write a letter else program skip this action.
thanks for any tip ;)
You can do this by changing the terminal settings (see man termios) using luaposix (on POSIX machines only, obviously):
local p = require( "posix" )
local function table_copy( t )
local copy = {}
for k,v in pairs( t ) do
if type( v ) == "table" then
copy[ k ] = table_copy( v )
else
copy[ k ] = v
end
end
return copy
end
assert( p.isatty( p.STDIN_FILENO ), "stdin not a terminal" )
-- derive modified terminal settings from current settings
local saved_tcattr = assert( p.tcgetattr( p.STDIN_FILENO ) )
local raw_tcattr = table_copy( saved_tcattr )
raw_tcattr.lflag = bit32.band( raw_tcattr.lflag, bit32.bnot( p.ICANON ) )
raw_tcattr.cc[ p.VMIN ] = 0
raw_tcattr.cc[ p.VTIME ] = 10 -- in tenth of a second
-- restore terminal settings in case of unexpected error
local guard = setmetatable( {}, { __gc = function()
p.tcsetattr( p.STDIN_FILENO, p.TCSANOW, saved_tcattr )
end } )
local function read1sec()
assert( p.tcsetattr( p.STDIN_FILENO, p.TCSANOW, raw_tcattr ) )
local c = io.read( 1 )
assert( p.tcsetattr( p.STDIN_FILENO, p.TCSANOW, saved_tcattr ) )
return c
end
local c = read1sec()
print( "key pressed:", c )
The lcurses (ncurses for Lua) Lua library might provide this. You would have to download and install it. There is an example of how to check for keypress only at Create a function to check for key press in unix using ncurses, it is in C but the ncurses API is identical in Lua.
Otherwise, you will have to create a Lua extension module using the C/C++ API: you would create C function that you call from Lua, and this C function then has access to the OS's usual function like getch, select, etc (depends if you are on Windows or Linux).

Game Maker not recognizing variable

Attempting to set up a targeting array for a MMO-style game in GameMaker8 Pro, I have this code in the create event for the player's character, which is and has been running perfectly fine:
j = 0
i = 0
g = 0
for (i=100000; i<1000000; i+=1) if instance_exists(i) {if i.object_index = enemy {global.ttarget[j] = i j+=1} if i.object_index = rk or i.object_index = sage {global.etarget[g] = i g += 1}}
global.rmtargets = j
global.etargets = g
Then running this code in the step event for the player character:
h = 0
g = 0
i = 0
for (i=0; i<global.rmtargets; i+=1) global.target[i] = 0
global.target[0]=101139
for (h = 0; h<global.rmtargets; h+=1){hv = -1
for (g = 0; g<global.rmtargets; g+=1){if global.ttarget[g].range > hv {hv = global.ttarget[g].range}}
global.target[h] = hv
global.ttarget[h] = -1}
Returns this error message:
ERROR in
action number 1
of Step Event
for object rk:
Error in code at line 8: for (g = 0; g<global.rmtargets; g+=1){if global.ttarget[g].range > hv {hv = global.ttarget[g].range}}
at position 61: Unknown variable range
Even though I have this in the create event for the enemy:
range = 0
range = distance_to_object(rk)
And I've used this sort of syntax all over:
global.target[target].threat[s] += damage
Help? Any ideas why Game Maker won't recognize the variable?
My best guess is that one or more of the enemy instances have been destroyed between the player create event and the step event where the error happens. Maybe a better solution would be to iterate over all the enemies using the with() construct, that is faster and you can be sure that all the instances you are working with actually exist.
try putting brackets around the object variable. I have had trouble references from a reference extension before.
(global.ttarget[g]).range
or even save it to a new variable
for (g = 0; g<global.rmtargets; g+=1)
{
curr_target = global.ttarget[g]
curr_target.range
}
Instead of using global. before each instance of the variable in the code, you could also initialize it with the command:
globalvar (variable), (variable2);
Then you would be able to use the variable without global. in front of it :)
If object rk is not the enemy then there is no global range variable detectable by object rk. Variables initialized without var or globalvar only apply for the object it was defined in.
First of all, put round brackets in if conditions.
Second you should give more informations about your environment and programming logic and IMO stop using all these global variables.
Anyway, from what i understood of what you're doing, try to use the with keyword:
with(global.ttarget[g]) {
other.hv = range;
}

Resources