How do I convert string to interger in AHK - autohotkey

I have this code below and I would like to get a string like "0,0" convert to integer and sum boths variable putting it on a new variable.
I was looking for solution in internet but without sucess.
code:
MouseMove, 238,282
MouseClickDrag, Left, 238,282, 238,282
Sleep, 200
Send, {CTRLDOWN}c{CTRLUP}
CLIPWAIT, 0.5
SaldoContabil = %ClipBoard% ; here is getting 0,0
Sleep, 400
MouseMove, 602,283
MouseClickDrag, Left, 602,283, 602,283
Sleep, 500
Send, {CTRLDOWN}c{CTRLUP}
CLIPWAIT, 0.5
ArredAcumulado = %ClipBoard% ; here is getting 0,0
Sleep, 400
baixa = %ArredAcumulado% - %SaldoContabil%

Add the following lines before the final calculation.
StrReplace just replaces the , with a . so from 0,0 you get 0.0, no further conversion is necessary.
SaldoContabil := StrReplace(SaldoContabil,",",".")
ArredAcumulado := StrReplace(ArredAcumulado ,",",".")

Related

Script modification(drag and drop)

I have simple script that looks for specified color pixel in restricted area then performs move mouse of this pixel to specified x,y coordinates it looks like this(control hold is added, because it needs to be pressed while moving stock):
#ifwinactive
F10::
PixelSearch, ItemX, ItemY, 1800, 600, 1700, 500, 0xFFE047, 1 , RGB FAST
if ErrorLevel = 0
Mousemove, ItemX, ItemY, 0
Send, {lbutton down}
sleep, 20
Send, {lctrl down}
Random x, 1600, 1700
Random y, 590, 655
Mousemove, x, y, 0
Send, {lbutton up}
Send, {lctrl up}
return
It works great but takes control over my MOUSE which I don't want, so I am trying to modify it to perform action without taking control over my mouse. I have tried to search, using controlclick but this couldn't handle dragging, then I have read about PostMessage which I don't clearly understand but I have come with this kind of script(not fully understand dll calls that's why most likely it doesn't work like intented):
#ifwinactive
x := 1650
y := 620
F10::
PixelSearch, ItemX, ItemY, 1900, 600, 1750, 500, 0xFFC661, 1, RGB Fast
CoordMode, Pixel, Screen
if !hWnd := DllCall("WindowFromPoint", Int,ItemX, Int,ItemY, Ptr)
if !hWnd := DllCall("WindowFromPoint", UInt64,(ItemX&0xFFC661)|(ItemY<<32), Ptr)
if !hWnd := DllCall("WindowFromPoint", UInt64, x|(y << 32), Ptr)
return
VarSetCapacity(POINT, 8, 0)
NumPut(ItemX, POINT, 0, "Int"), NumPut(ItemY, POINT, 4, "Int")
DllCall("user32\ScreenToClient", Ptr,hWnd, Ptr,&POINT)
ItemX := NumGet(POINT, 0, "Int"), ItemY := NumGet(POINT, 4, "Int")
if ErrorLevel
PostMessage, 0x0200, 0, ItemX&0xFFC661|ItemY<<16,, % "ahk_id " hWnd ;WM_MOUSEMOVE
sleep, 5
PostMessage, 0x0201, 0, ItemX&0xFFC661|ItemY<<16,, % "ahk_id " hWnd ;WM_LBUTTONDOWN
sleep, 5
PostMessage, 0x0200, 0, x|y<<16,, % "ahk_id " hWnd ;WM_MOUSEMOVE
sleep, 5
PostMessage, 0x0202, 0, x|y<<16,, % "ahk_id " hWnd ;WM_LBUTTONUP
sleep, 5
return
There is problem with this scirpt it actually act like this: Search for pixel>if it's there>perform post messages under my cursor(actually taking things under my mouse to specified x,y.
While what I want is to look for pixel, pick this pixel and move it. Is it even possible without taking control over my mouse?
EDIT!
NEW CODE
#ifwinactive
CoordMode, Pixel , Screen
x := 1650
y := 620
lparam := pX | (pY << 16)
lparam2 := x | (y << 16)
f10::
PixelSearch, pX, pY, 1900, 1000, 1750, 500, 0xFFE047, 1, Fast
if Errorlevel
{
PostMessage, 0x0200, 0, %lparam%,, ahk_exe something.exe ;WM_MOUSEMOVE
sleep, 10
PostMessage, 0x0201, 0x0001, %lparam%,, ahk_exe something.exe ;WM_LBUTTONDOWN
sleep, 10
PostMessage, 0x0200, 0x0001, %lparam2%,, ahk_exe something.exe ;WM_MOUSEMOVE
sleep, 10
PostMessage, 0x0202, 0, %lparam2%,, ahk_exe something.exe ;WM_LBUTTONUP
}
return

Need help on AHK script closing when pixel change

Hello I am fairly new to coding and I’m making a programme for a game I play on AHK, I’m trying to code a script so that when a pixel changes colour on my screen the script will completely stop whilst remaining part of the loop. The main code works but I've tried to add a system where the script will stop running if a pixel changes colour. Thanks for the help in advance.
Esc::ExitApp
+r::
sleep, 1000
Send, {e down}
Send, {e up}
sleep, 10750
loop {
PixelGetColor, color1, 949, 269
if(color1 = “0xA6A6A6”)
sleep, 500
SendInput {Esc}
IfWinActive ahk_exe FiveM_GTAProcess.exe
sleep, 5550
Send, {e down}
Send, {e up}
sleep, 500
MouseClick Left, 649, 390
sleep, 500
MouseClick Left, 964, 484
sleep, 500
MouseClick Left, 1311, 415
sleep, 500
loop, 4
{
MouseClick Left, 964, 484
sleep, 500
}
sleep, 500
MouseClick Left, 720, 415
sleep, 500
}
Add Break after your if:
if(color1 = “0xA6A6A6”)
Break
if(color1 = “0xA6A6A6”)
{
sleep, 500
SendInput {Esc}
}

How can I find the problem in the script I wrote in AHK

I'm making a macro of a game, and I tried a different thing, and now it doesn't seem to be working. I added if Lf := 1 and if Rg := 1 which are variables to represent the radio indicator. Here's the code:
F9::
toggle :=!Toggle
if (toggle)
{
SetTimer, Repeat, 100
Repeat()
}
else
SetTimer, Repeat, Off
return
Repeat()
{
Click, 920, 885
Sleep, 200
if (Lf := 1)
{
Click, 755, 530
Sleep, 200
Click, 550, 530
}
else if (Rg := 1)
{
Click, 1165, 530
Sleep, 200
Click, 1370, 530
}
Sleep, 200
Send, {Space Down}
Sleep, %MilSecOne%
Sleep, %MilSecOne%
Send, {Space Up}
Sleep, 200
}
It doesn't work as I expected.
The := operator is used to assign a value (which will be the result of an expression) to a variable.
So right now what you're doing, is assigning the number 1 to your variables, and then checking with the if-statement if the value of that variable evaluates to true.
(And it always will, non-zero numbers evaluate to true)
You're looking for the = operator.
In an expression (which is what your if ( ) -statement is) it compares values, rather than assigns text to a variable, which is what it does in a legacy statement.
So, change
if (Lf := 1)
else if (Rg := 1)
to
if (Lf = 1)
else if (Rg = 1)
Edit:
I'm also noticing that the variables Lf and Rg doesn't seem to exist?
At least not in that function's scope.
I hope they're defined as super-global somewhere else.
Otherwise there's no way that code is going to work.

My script breaks down at some point, I've eliminated all the syntax errors the debugger was able to spot

This is a script that is supposed to use the windows snipping tool to sequentially screencap pictures from an online gallery. If anyone can spot the problem that would be much appreciated.
#SingleInstance, Force
a := 112
name :=1
x:: Pause, Toggle
y:: ExitApp
Loop, a
{
MouseClickDrag, Left, 1300, 210, 645, 140
Sleep, 100
MouseClick, Left, 1277, 1038, 0, 5
sleep, 100
MouseClick, Left, 838, 64, 0, 5
sleep, 100
SendInput, %name%
name ++
sleep, 100
SendInput, {Enter}
Sleep, 100
MouseClickDrag, Left, 670, 13, 1393, 153
Sleep, 100
MouseClick, Left, 500, 490, 0, 5
Sleep, 300
MouseClick, Left, 500, 490, 0, 5
SendInput, {Right}
}
Two problems in it.
Firstly, your loop is unreachable code.
Code execution stops when your first hotkey label is encountered. This is called the Auto-execute Section.
Secondly, loop doesn't take an expression to the first parameter. It takes a legacy text parameter. So you'd either want to use the legacy way of referring to a variable, which would be %a%, but personally I'd push you towards using the modern expression syntax and forcing an expression to that parameter by starting the parameter off with a % followed up by a space. So Loop, % a.
To read more about legacy syntax vs expression syntax, see this page of the documentation.
Here's your fixed script:
#SingleInstance, Force
a := 112
name := 1
Sleep, 3000
Loop, % a
{
MouseClickDrag, Left, 1300, 210, 645, 140
Sleep, 100
MouseClick, Left, 1277, 1038, 0, 5
Sleep, 100
MouseClick, Left, 838, 64, 0, 5
Sleep, 100
SendInput, % name
name++
Sleep, 100
SendInput, {Enter}
Sleep, 100
MouseClickDrag, Left, 670, 13, 1393, 153
Sleep, 100
MouseClick, Left, 500, 490, 0, 5
Sleep, 300
MouseClick, Left, 500, 490, 0, 5
SendInput, {Right}
}
;this return here ends the auto-execute section
;but of course, in this specific case it's totally
;useless since the next line is a hotkey label
;which would also stop the auto-execute section
return
;even though the code execution gets stuck inside the loop,
;hotkeys can be specified down here
;they're created even before the auto-execute section starts
x::Pause, Toggle
y::ExitApp

How to change the loop?

The script is searching for a certain text in the clipboard. When found, it shows a MsgBox.
I would like this script to stop when the text has been found. How to achieve that?
#Persistent
MouseMove, 821, 700
Sleep, 500
MouseClick, Left
Sleep, 500
Loop, 5
{
Send, ^c
Sleep, 500
Send, {PgDn}
}
OnClipboardChange:
If InStr( Clipboard, "Part3" )
SetTimer, PopupMsgBox, -1
Return
PopupMsgBox:
Msgbox, Part3 Found
Return
#Persistent
clip_search := "Part3"
MouseMove, 821, 700
Sleep, 500
MouseClick, Left
Sleep, 500
Loop, 5
{
Send, ^c
ClipWait
If InStr( Clipboard, clip_search )
{
MsgBox, % clip_search " Found."
Break
}
Sleep, 500
Send, {PgDn}
}