Clipboard Confusion?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
cnikitopoulos94
Posts: 13
Joined: 12 Dec 2018, 16:43

Clipboard Confusion?

16 Dec 2018, 22:52

Hello All,

Firstly I just wanted to say thanks for having me in the forum. I have some experience with Jitbit Macrorecorder, but they dont have supportive variables.

I have been trying to establish the following actions but cant seem to get the following to work.

1. (Compare clipboard value (using key strokes LControl (Down), C (press), LControl (Release))

Code: Select all

If Clipboard value > 10 then 
perform action
else
perform other action
Simply having problems with compare clipboard to a fix number

2. How to store current clipboard value (If only its greater then fixed integer so when it constantly clipboards it wont restore it with a new value UNLESS the new Clipboard value exceeds old Clipboard value.)

Code: Select all

If Clipboard Value1 > Clipboard value 2 then
Move mouse 
Click 
If else
Move Mouse 
Click 
if end if 
Thank you in advance just trying to make some cool macros and share it with the community.
User avatar
Scr1pter
Posts: 1271
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Clipboard Confusion?

16 Dec 2018, 23:45

Hi and welcome.
This code checks if the Clipboard content is higher than 10 or not.

Code: Select all

1::
if Clipboard > 10 ; If Clipboard value is higher than 10:
{
  MsgBox, Yes, it's higher than 10! ; MessageBox 1
}
else ; If it's 10 or lower than 10:
{
  MsgBox, No, it's not higher than 10! ; MessageBox 2
}
return
If you want to change its value, you can simply make:

Code: Select all

2::
if Clipboard > 10 ; If Clipboard value is higher than 10:
{
  Clipboard = 10 ; Set Clipboard value to 10
}
return
Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
cnikitopoulos94
Posts: 13
Joined: 12 Dec 2018, 16:43

Re: Clipboard Confusion?

17 Dec 2018, 00:06

Hey Scr1pter thanks for the response !

Thanks for the warm welcome , much appreciated.

So i ended up doing the following code to be able to actual read the integers off the clipboard content.. hope this helps any body in advance..

Any troubles will the macro and I will continue to post Cheers!

Code: Select all

    Click, Left, , Down
    Sleep, 500
    Click, 1246, 760 Left, Up
    Sleep, 500
    Click, Left, , Up
    Sleep, 500
    ControlGetText, Clipboard, , A
    If Clipboard > 10  ; We copied the number, now verify the number is greater then 10 
    {
        Click, 1368, 621 Left, 1
        Sleep, 500
    }
User avatar
Scr1pter
Posts: 1271
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Clipboard Confusion?

17 Dec 2018, 00:43

You're welcome!

Just a question:
What exactly is your script doing?
Perhaps there might be also other ways to realize it.
I don't know your programming experience.

Your sleep times look pretty long.

P.S. When writing codes (no matter if macro recordings), it's never bad to add some comments afterwards - this will help you trace the whole process.

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
cnikitopoulos94
Posts: 13
Joined: 12 Dec 2018, 16:43

Re: Clipboard Confusion?

17 Dec 2018, 01:22

So Im trying to make a script where its just simply analyzing numbers from a game that I play.

So essentially it would work like this

Sequence 1

If Clipboard > 10 then
Execute left click at (X, Y)
If Clipboard <10 then
Change settings of the game
Execute left click at (X,Y)

The adaptable variable is "Find Image" synchronizing it as it changes so if one image isnt found it will continue until the next image is found . Which when the "Change settings of game" occurs it will then not search the same image from sequence 1, but now looking for the image on Sequence 2 be

Sequence 2
If Clipboard value > 34 then
Execute left click at (X,Y)
Else
Execute left click at (X,Y)
Execute left click at (X,Y)
End

As for programming experience, I use to do code on LUA a few years back (forgot alot of it by now). I also put the delay for that period , just so I can assure its executing commands properly. Also do still have some questions , help is always appreciated.

1.) After each round of the game due to this synchronization , do I have to "Reset" clipboard value after each result? or does it automatically override it with new clipboard value?
2.) How do I necessarily hold one variable without it being overwritten by the Clipboard? I.e. ( I would want it to run a certain setting until a certain amount of energy is made, but this amount of energy that needs to be made is the amount that we lost from the previous sequence?)

This is what I have now, but its having problems running the else portion . Thanks again in advance.

Code: Select all

CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 0, 0, 1920, 1080, C:\Users\ancie\Documents\Macro\Capture.PNG
CenterImgSrchCoords("C:\Users\ancie\Documents\Macro\Capture.PNG", FoundX, FoundY)
If ErrorLevel = 0
	Click, %FoundX%, %FoundY%, 0
If ErrorLevel = 0
{
    Click, 846, 760, 0  ; Checking if we won last round or not
    Sleep, 500
    Click, Left, , Down
    Sleep, 500
    Click, 1246, 760 Left, Up
    Sleep, 500
    Click, Left, , Up
    Sleep, 500
    ControlGetText, Clipboard, , A
    If Clipboard > 10  ; We copied the number, now verify the number is greater then 10 
    {
        Click, 1368, 621 Left, 1
        Sleep, 500
    }
    Else ; Ok now we lost last round now lets change settings. 
    {
        Click, 943, 459 Left, Down
        Sleep, 10
        Click, 1040, 459 Left, Up
        Sleep, 10
        Click, 1368, 621 Left, 1
        Sleep, 500
    }
}
User avatar
Scr1pter
Posts: 1271
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Clipboard Confusion?

17 Dec 2018, 02:05

I assume you worked with Logitech lua.
That was my first real programming language too.
(By real I mean intense usage.)

Regarding your questions:
1)
Normally, you don't need to reset the Clipboard value.
Once a new value gets added to the Clipboard, it overwrites the old one.
But if you want to be sure, you can still reset it after you don't need it:
Clipboard = (looks strange, but it actually means: Clipboard = empty)

2)
Just use a helper variable.
clipboardBackup := Clipboard (You can call the helper variable as you want)
Later, you can just restore it:
Clipboard := clipboardBackup

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
cnikitopoulos94
Posts: 13
Joined: 12 Dec 2018, 16:43

Re: Clipboard Confusion?

17 Dec 2018, 02:11

It was actually IndicoreSDK (FXCM , forex automated trading , or indicators).
haha but yes definitely real usage there.

1.) Oh boy I feel like a scrub. what different ways are there to "Copy" to clipboard? meaning do i have to use "Keystrokes" (Ctrl Hold down +Press C+ Ctrl Release)? What other ways are there? based on the code I provided before it ignores "else" and constantly just executes as if the number is always above "10" even when it isn't. (Fixed).
2.) Will check this one as I go further.
User avatar
Scr1pter
Posts: 1271
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Clipboard Confusion?

17 Dec 2018, 04:00

Yes, you will have a lot of fun with AHK - believe me :)

Btw, you can delete your other thread:
https://autohotkey.com/boards/viewtopic ... 76&t=60056

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
cnikitopoulos94
Posts: 13
Joined: 12 Dec 2018, 16:43

Re: Clipboard Confusion?

18 Dec 2018, 22:36

Thanks for deleting the other thread for me Scr1pter.

Yea I definitely see alot of the connections between lua and this macro. Sort of is a "debugger", or say the least reminds me of the one I had with lua.

Some are just assigning global variables (Some local) in order to also put "User input" allowing it to be more of a text start up.

For instance, I could implement it where user first puts there defined settings then applies it to the rest of the macro based on the user input. This way people wont have to change every input manually through "Pulovers Macro Creater" rather , a message box displaying all input.

The only thing is I will have to adjust my ways of assigning "User input" to "Global Variables".

Are we allowed to use notepad++ then open it to the Macro? Feel like typing some of this would be alot easier rather then simply finding all the commands through dropdown menus.

Cheers for the assitance! :thumbup:

P.s. I actually want to be a contributing member to the community, but just helping me with some direction can provide me a better influence to my work and future assitance with other peoples questions as well.
User avatar
Scr1pter
Posts: 1271
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Clipboard Confusion?

19 Dec 2018, 06:52

Of course you are allowed to use Notepad++ or any other editor.
I, for example, use my programming keys to create commands instead of typing them.
Saves a lot of time and typos are practically impossible.
I don't work with simple macros so much anyway.
(When I started with AHK, I did everything with macros because that was all I knew.)

P.S. I did not delete your other thread because I don't have that permission.

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
cnikitopoulos94
Posts: 13
Joined: 12 Dec 2018, 16:43

Re: Clipboard Confusion?

23 Dec 2018, 11:41

Thats awesome Scr1pter, thanks for the sound advice.
I imagine thats pretty impressive. When it would come to extensive lines of code, that seems highly practical.

I havent been able to so to speak, work on my macro as much as i imagined but did fix alot of the few key decisions that it was making flawed. Is there by any chance I can pm you rather then posting it on the forum? I feel it would be alittle bit more convenient for me as well as being less of a distraction to everybody else.

Thanks in advance!
User avatar
Scr1pter
Posts: 1271
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Clipboard Confusion?

23 Dec 2018, 12:39

It's fine for me, but normally it's always better to post public, because other users can either learn or help.

One hint when working with macros:
I assume you will have a lot of lines which are more or less the same.
For example:

Code: Select all

Send {Tab}
Sleep, 55
Send {Tab}
Sleep, 80
Send {Tab}
Sleep, 10
Send {Tab}
Sleep, 33
Send {Tab}
Sleep, 45
Send {Tab}
Sleep, 95
You can put those lines all together:

Code: Select all

Send {Tab 6} ; Press 6 times Tab
Also, when you repeat certain parts in your macro, you can put them as a function and call that function.
Example:
Instead of

Code: Select all

F1::
.
.
.
Send a ; Mark all
Sleep, 20
Send ^c ; Copy everything
ClipWait, 0.1 ; Wait 100 ms until the Clipboard contains data
Send {Del} ; Delete Marked lines
Sleep, 20
Send this is a test ; Send this string
.
.
.
Send a ; Mark all
Sleep, 20
Send ^c ; Copy everything
ClipWait, 0.1 ; Wait 100 ms until the Clipboard contains data
Send {Del} ; Delete Marked lines
Sleep, 20
Send this is a test ; Send this string
.
.
.
return
You can write it this way:

Code: Select all

F1::
.
.
.
Copy_Everything() ; Call the function to perform specified operations
.
.
.
Copy_Everything() ; Call the function to perform specified operations
.
.
.
return

Copy_Everything() ; Choose any meaningful function name
{
  Send a ; Mark all
  Sleep, 20
  Send ^c ; Copy everything
  ClipWait, 0.1 ; Wait 100 ms until the Clipboard contains data
  Send {Del} ; Delete Marked lines
  Sleep, 20
  Send this is a test ; Send this string
}
I don't know your programming level, but since you mention you work with macros, I guess your codes will be much longer than needed.
It's normal, because a macro recorder won't know when it's useful to create a function and when not - it's just a recorder.
I bet it doesn't put same keys together, as I showed you in example 1.

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
cnikitopoulos94
Posts: 13
Joined: 12 Dec 2018, 16:43

Re: Clipboard Confusion?

23 Dec 2018, 14:53

Thanks Scripter! Yea, it just seems alittle bit more difficult to use when your just using the interface, (Pulovers). Instead , I prefer Notepadd++ .

Lol so many questions, even though they are a bit novice. Starting one place always helps with the next leap of challenging myself. I figured based on everything that I attempt to accomplish, itd be better if i laid out all the questions I have that way, I can implement and see if I have any problems there on foward. Your time is valuable and I appreciate you taking the time to help me out.

I want to operate the Macro to work as such. What is the proper command to call the next macro? For instance.

Code: Select all

 Macro 1
[If clipboard>X then 
	   then upload (Upload different Macro) (file append?)
end

Code: Select all

 
^^^^ ( never mind figured it out , simple GoTo / label statements. After importing macro just simply put Goto "Label". )
Macro 2	  
Energy Amount== Clipboard + X
	   --- Then So now will run this macro until conditions are met which if they are back to macro one 
If Clipboard > Energy Amount then
	   ------ Upload Macro 1)
end

So now simply Im stating that "energy amount" is the clipboard value from Macro 1 + X and if Macro 2 Clipboard is greater then energy amount then go back to macro 1? ( Correct?)
User avatar
Scr1pter
Posts: 1271
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Clipboard Confusion?

23 Dec 2018, 18:36

Yes, it's always better to create separate threads.
I mean, AHK provides so many functions and possibilities, so that it makes no sense to put many questions in 1 thread.
(Otherwise a thread could never be marked as solved.)

Regarding your question:
To be honest it's difficult for me to follow the exact flow.
Especially the syntax looks strange to me.
Those codes are directly in Pullover's editor?

How do you start them anyway?
Your first scripts (which you posted here) were normal AHK scripts.
This one is, at least to me, unknown.

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
cnikitopoulos94
Posts: 13
Joined: 12 Dec 2018, 16:43

Re: Clipboard Confusion?

24 Dec 2018, 02:51

Sorry for the confusion scr1pter. Figured out one solution to the problem.

These should be the last questions for this topic.

1.) How do I implement this code on pullover?

Code: Select all

Clipboard =
2. What's the proper way of uploading it to notepad++? (Tried doing it and it doesnt highlight any variables and repeats the lines from pullover onto the actual script)
User avatar
Scr1pter
Posts: 1271
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Clipboard Confusion?

24 Dec 2018, 06:30

No problem.

Regarding 2)
It doesn't highlight anything, because it doesn't know how to handle ahk files.
You should check this thread which shows how to setup Notepad++ for AHK:
https://www.autohotkey.com/boards/viewt ... ?f=60&t=50
(Alternative solution: You assign some scripting language to ahk files which is similar.)

The repeating of the lines is something you'll have to do manually.
Maybe you can find some helper scripts which do that.

If not, feel free to use the script which I've just created:

Code: Select all

;Replace same code lines (e.g instead of 5x Send e it will make a Send {e 5} out of it
F1:: ; F1 (you can change the key of course, but avoid using Ctrl in this case)
Send ^c ; Copy selection
ClipWait, 0.1 ; 100 ms buffer to save data
Loop, Parse, Clipboard, `n, `r ; Read the content of the Clipboard and split it on each line-break
{
  if !InStr(A_LoopField, "Send") ; If line does not contain the keyword "Send":
  {
    continue ; Skip this round (in order not to raise amount)
  }
  if InStr(A_LoopField, "Send") ; If line contains the keyword "Send":
  {
    amount++ ; Increase amount by 1
    saveLine := A_LoopField ; Save this line
  }
} ; End of loop
if saveLine contains } ; If line contains } (e.g. Send {Tab}
{
  saveLine := StrReplace(saveLine, "{") ; Remove {
  Sleep, 5
  saveLine := StrReplace(saveLine, "}") ; Remove }
}
saveLine := StrReplace(saveLine, "Send ", "Send {") ; Replace Send by Send {
Sleep, 5
Clipboard = %saveLine% %amount%}`nSleep, 10 ; Example results: Send {Enter 10}, Line-Break, Sleep 10 / Send {r 5), Line-Break, Sleep 10
ClipWait, 0.1 ; 100 ms buffer to save data
Send ^v ; Paste data
return
How to use it:
After compiling it, mark a code block which contains the same keys (only the same keys!).
So, if you find a block like:

Code: Select all

Send {Tab}
Sleep, 55
Send {Tab}
Sleep, 80
Send {Tab}
Sleep, 10
Send {Tab}
Sleep, 33
Send {Tab}
Sleep, 45
Send {Tab}
you will mark it and press F1 (or the hotkey you assigned to).

My script will merge them all together and make just two lines out of it:
In this case:

Code: Select all

Send {Tab 11}
Sleep, 10
(If it makes something wrong, you can always undo it with Ctrl+Z.)

There are surely other ways to realize that, but I just wanted to try it out by myself.
(It took just like 10 minutes I think.)

I can't answer the first question.
You better ask here:
https://www.autohotkey.com/boards/viewt ... &start=960

P.S. I believe you cannot use my script in the Pullover editor. Just use it in Notepad++ on some real AHK code.

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
cnikitopoulos94
Posts: 13
Joined: 12 Dec 2018, 16:43

Re: Clipboard Confusion?

24 Dec 2018, 17:06

Thanks again Scriptor for the response. As of right now my main motive is to be able to play it through PMC (Pulovers Macro), mainly because of what i intend to use it. Once it is finished I intend to focus more on the AHK format, but that will require alittle bit more time and probably a debugger (Saw some responses on Debuggers for AHK on Notepadd++.)

Your solution would help, was wondering if you could assist me. I have been having a tough time with storing the variable. I dont know why its not working, but this is the full end of the Macro which will look siginificantly different with the final product. I devoted alot of time past few days (Since its the holidays), to finish this once and for all. Yet, I still couldnt find a way to fix this. Im starting to get aggravated with PMC (Due to its complex nature of just simply not allowing us to just modify via text.)

Hopefully you can help me with this one, as I dont understand why its not going to according to plan. I will explain as much as i can.

Code: Select all

CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 0, 0, 1920, 1080, C:\Users\ancie\Documents\Macro\Capture.PNG
CenterImgSrchCoords("C:\Users\ancie\Documents\Macro\Capture.PNG", FoundX, FoundY)  ; Image search ( Future note , may be able to get rid of If imagepixel found command by only letting it operate if image IS found, breaking if not). 
If ErrorLevel = 0  ; Found image 
{
    Click, 846, 760, 0  ; Checking if we won last round or not
    Sleep, 100
    Click, Left, , Down  ; Click Down
    Sleep, 100
    Click, 1246, 760 Left, Up  ; Let Go
    Sleep, 100
    Click, Left, , Up  ; Let go (Confirm again)
    Sleep, 100
    Send, {LControl Down}
    Sleep, 100
    Send, {c}
    Sleep, 100
    Send, {LControl Up}  ; (Copying to Clipboard)
    Sleep, 100
    If Clipboard > 10  ; 
    {
        SendEvent, {Click, 1228, 556, Left Down}{Click, 1308, 558, Left Up}  ; Go to "Energy" amount. 
        Sleep, 500
        Send, {LControl Down}
        Sleep, 100
        Send, {c}
        Sleep, 100
        Send, {LControl Up}  ; (Copying to Clipboard)
        Sleep, 100
        If Clipboard >= Account
        {
            Click, 1895, 26 Left, 1
            Sleep, 500
        }
        If Clipboard < Account
        {
            Click, 1368, 621 Left, 1  ; Hit "Play"
            Sleep, 100
            Click, 1769, 249 Left, 1  ; (Ridding the Blue highlighter)
            Sleep, 100
        }
    }
    If Clipboard <= 10  ;  
    {
        SendEvent, {Click, 1228, 556, Left Down}{Click, 1308, 558, Left Up}  ; Go to "Energy" amount. 
        Sleep, 500
        Send, {LControl Down}
        Sleep, 100
        Send, {c}
        Sleep, 100
        Send, {LControl Up}  ; (Copying to Clipboard)
        Sleep, 100
        Clipboard := Account+2
        Click, 1368, 621 Left, 1  ; Hit "Play"
        Sleep, 100
        Click, 1769, 249 Left, 1  ; (Ridding the Blue Highlighter)
        Sleep, 100
    }
}
So essentially what Im trying to get it to do is just simply play the loop over and over until it Clipboard >= Account. Once it hits that it will exit the screen (the coordinates are listed there.) Ive been struggling with this more then any other course brought my way by this macro. Right now Im just :headwall: because it doesnt make sense! Anyways hope this gives you enough information to help me out. Again your time is much appreciated, and hope you have a wonderful holiday.
User avatar
Scr1pter
Posts: 1271
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Clipboard Confusion?

24 Dec 2018, 17:33

Hi,

Where does the variable Account come from?
It is inside of your code 3 times (and you compare the Clipboard to it), but I don't see anywhere its value.
Is this really the full code?
If you want to save the Clipboard value to another variable, you will have to work with
Account := Clipboard
(For example)

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
cnikitopoulos94
Posts: 13
Joined: 12 Dec 2018, 16:43

Re: Clipboard Confusion?

24 Dec 2018, 17:43

This isn't the full code. I tried to break it down to test it, to see if it would work ( Account+2).
So the Account is suppose to have the value of "Clipboard+2". Its suppose to assign the value of "Account" once we lost the last round (Which it checks every round).
  • Account := Clipboard+2
It will only store the value when the IF condition is met.


FIXED!!!!!!!!!!!!!! I had to use the following

If clipboard >= %Account%

I had to use percentage to connect the variables... DUH!!! Thank you Scripter!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jaka1 and 142 guests