Function hierarchy and if( ){}

Get help with using AutoHotkey and its commands and hotkeys
Posts: 1
Joined: 25 Apr 2017, 10:53

Function hierarchy and if( ){}

25 Apr 2017, 10:58

I have been using AHK for a while now, but for simple send commands. Im trying to do some more advanced code but I hitted a wall.
Im trying to copy some text to be placed into a variable via Clipboard, so far so good.
The issue comes when i try to paste it back, I believe is related to the hierarchy but i can figure it out.
Any help would be appreciated

Code: Select all

titleString:= title ; attemp at global strings
textString:= text ;^^^^^
reset() ; quick reset of the AHK
	msgbox,,, reset, .3 
	Run, "C:\Users\dmrjmrd\Desktop\AutoHotkey_1.1.24.04\CtoCS.ahk" 

	global titleString:= title ; my understanding is that this would pull from the global variable...?
	global textString:= text
	clipboard =
	x:= x
	if(x == 1) ; copies selected text into title string
		send, ^c 
		titleString := clipboard
		msgbox,,, %titleString% copied,5 ; lets user know selection
	else if(x == 2) ; same as the first if
		send, ^c
		textString := clipboard
		msgbox,,, text copied,.1 ; quick feedback letting know the selection happened
	else if(x == 3) ; here is the issue
		msgbox,,, %titleString% + %textString% ,5 ; the message return only " + "
		clipstring = <hr><h1>%titleString%</h1><hr><p>%textString%</p><p>&nbsp;</p> ; some html code that needs the previous strings added to it.
		msgbox,,, %clipstring%, 5 ; confirm that the neither the title string or the text are present on the html string
		clipboard = %clipstring%
		send, ^v
	else if(x == 4)
		msgbox,,, you shouldnt be here D:, .5

	; reset()
User avatar
Posts: 404
Joined: 30 Sep 2014, 10:32

Re: Function hierarchy and if( ){}

25 Apr 2017, 12:55

This one:
global titleString:= title ; my understanding is that this would pull from the global variable...?
There isn't any variables here named "title".

x:= x
What are you suppose do do here?

send, ^c
My experience is that the "keypress" is too fast for some programs, that is the program cannot respond quick enough. I always use either:
send, {Ctrl down}c{Ctrl up} or alternative use SetKeyDelay if you don't want to put a sleep between send, {Ctrl up} and send, {Ctrl up}.
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Function hierarchy and if( ){}

25 Apr 2017, 21:01

I always use ^c. The bigger problem I see is that there is no Sleep or ClipWait between send, ^c and the reference to clipboard.

global titleString:= title declares that within the function, "titleString" should refer to a global variable. It also replaces whatever value that variable had with the value of another variable, title. Your script shows two variables named title (one global outside the function, and one local to the function, because it has not been declared), and neither of them have apparently been assigned a value.

Maybe you meant to use the literal word "title". In that case, use quotation marks.

Return to “Ask For Help”

Who is online

Users browsing this forum: Rohwedder, tmplinshi and 41 guests