예제 #1
0
    def __call__(self, imagePath, evtID, cType, evtF, evtNF):
        script = "\nSysGet, VirtualWidth, 78\nSysGet, VirtualWidth, 79"
        script += "\nImageSearch, imageX, imageY, 0, 0"
        script += ", %A_ScreenWidth%, %A_ScreenHeight%, " + imagePath
        if cType != 0:
            script += "\nif ErrorLevel = 0"
            if cType == 1:
                script += "\n    Click %imageX%, %imageY%, left"
            if cType == 2:
                script += "\n    Click %imageX%, %imageY%, 2"
            if cType == 3:
                script += "\n    Click %imageX%, %imageY%, right"

        script = replaceEgVars(script)
        ImgScript = ahk.Script()
        ImgScript.variable("imageX", int)
        ImgScript.variable("imageY", int)
        ahk.execute(str(script))
        errorLevel = ImgScript.ErrorLevel
        if evtID:
            evtID += "."
        if errorLevel == 0 and evtF == True:
            eg.TriggerEvent(evtID + "ImageFound",
                            prefix="AHK.ImageSearch",
                            payload=[ImgScript.imageX, ImgScript.imageY])
        if errorLevel == 1 and evtNF == True:
            eg.TriggerEvent(evtID + "ImageNotFound", prefix="AHK.ImageSearch")
        if errorLevel == 2:
            eg.PrintError("There was an error. Try another image format.")
예제 #2
0
 def store(cmd):
     """execute replacement for mock."""
     # Object in outer scope used in closure to store a value
     inner_delay.append(int(ahk.get("A_ControlDelay")))
     if 'send' not in cmd.lower():
         #print cmd, inner_delay
         ahk.execute(cmd)
예제 #3
0
 def test_02_ScriptVariable(self):
     """Testing creating and using variables through a Script object."""
     value = 5
     script = ahk.Script()
     # Define our good variable
     script.variable('test', int, value)
     # Test expected exceptions
     with self.assertRaises(AttributeError):
         script.function('_badname')
         script.function('function')
         script.function('test')
     # Test getting variable value
     self.assertEqual(
         script.test,
         value,
         msg="Variable value {0} doesn't match expected {1}!".format(
             script.test, value))
     # Test setting variable value
     value = 10
     script.test = 10
     self.assertEqual(
         script.test,
         value,
         msg="Variable value {0} doesn't match expected {1}!".format(
             script.test, value))
     # Test outside modification
     ahk.execute("test := test+5\n")
     self.assertEqual(
         script.test,
         value + 5,
         msg="Variable value {0} doesn't match expected {1}!".format(
             script.test, value + 5))
예제 #4
0
파일: test_ahk.py 프로젝트: kelvinwop/pyahk
 def test_04_execute(self):
     """Testing executing script strings."""
     val = 0
     arr = [5, 6, 3, 7, 2, 4, 1, 8, 9]
     ahk.start()
     ahk.ready()
     # First set a test variable to a known value
     self.assertTrue(ahk.set("test", val),
                     msg="Setting value reported as failed by ahk!")
     # Execute a command that changes the value
     self.assertTrue(ahk.execute("test := test+1"),
                     msg="Execute reported failure!")
     # Check the value has changed, and is correct
     value = int(ahk.get("test"))
     self.assertNotEqual(val, value, msg="Value unchanged after execution?")
     self.assertEqual(
         value,
         1,
         msg="Unexpected value {0} after execution!".format(value))
     # Execute a more complicated set of commands and check the result
     self.assertTrue(ahk.execute("arr={0}\nsort arr, N D,".format(",".join(
         str(i) for i in arr))),
                     msg="Execute reported failure!")
     value = ahk.get("arr")
     arr = ",".join(str(i) for i in sorted(arr))
     #print "result:\n\t{0}\n\t{1}".format(value, arr)
     self.assertEqual(
         arr,
         value,
         msg="Unexpected result:\n\t{0} not equal to\n\t{1}".format(
             value, arr))
예제 #5
0
def openPortals():
    try:
        ahk.start()
        ahk.ready()
    except:
        pass
    urls =['www.naver.com','www.zum.com','www.daum.net','www.auction.co.kr','http://www.liveman.co.kr']
    for url in urls:
        cmd = 'Run,iexplore.exe %s,,Hide' %url
        try:
            ahk.execute(cmd)
            time.sleep(60*5)
        except:
            pass
        time.sleep(5.0)
예제 #6
0
def check_ahk():
    global queue_ind, queue_max
    q = ahk.get('q' + str(queue_ind + 1))

    if q != '':

        print(q, queue_ind)

        try:
            js = json.loads(q)
            threading.Thread(target=parse_msg, args=[js]).start()
        except:
            pass
        finally:
            ahk.execute('q{}:=""'.format(queue_ind + 1))
            queue_ind = (queue_ind + 1) % queue_max

    threading.Timer(1.0, check_ahk).start()
예제 #7
0
    def __call__(self, outVar, title, prompt, password, width, height, xPos,
                 yPos):
        script = "\nInputBox"

        if outVar != "eg." or outVar != "":
            script += ", output"
        else:
            eg.PrintError("No Output Variable Provided")
            return
        if title:
            script += ", " + title
        else:
            script += ", "
        if prompt:
            script += ", " + prompt
        else:
            script += ", "
        if password:
            script += ", hide"
        else:
            script += ", "
        script += ", " + width + ", " + height
        if xPos:
            script += ", " + xPos
        else:
            script += ", "
        if yPos:
            script += ", " + yPos
        else:
            script += ", "

        inputScript = ahk.Script()
        inputScript.variable("output", str)
        ahk.execute(str(script))

        print script
        print outVar + " = inputScript.output"
        try:
            if inputScript.ErrorLevel == 0:
                exec(outVar + " = inputScript.output")
            else:
                exec(outVar + " = ''")
        except:
            eg.PrintError("Problem with output variable.")
예제 #8
0
def openPortals(filename):
    try:
        ahk.start()
        ahk.ready()
    except:
        filename.write('url dntofile failed at %s\n' % time.ctime())

    urls = [
        'www.naver.com', 'https://www.youtube.com', 'www.daum.net',
        'www.auction.co.kr', 'https://www.youtube.com'
    ]

    for url in urls:
        cmd = 'Run,iexplore.exe %s,,Hide' % url
        try:
            ahk.execute(cmd)
            time.sleep(10.0)
        except:
            filename.write('url  failed at %s\n' % time.ctime())
        time.sleep(5.0)
예제 #9
0
def setStartPage(filename):
    try:
        ahk.start()
        ahk.ready()
    except:
        filename.write('running ahk.start or ready failed at %s\n' %
                       time.ctime())
        time.sleep(1.0)
    cmd = 'RegWrite, REG_SZ, HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Exploer\Main, Start Page, http://www.msn.com/ko-kr/?ocid=iehp/'
    rcode = ahk.execute(cmd)
    if not rcode:
        filename.write('running ahk.execute Regwrite failed at %s\n' %
                       time.ctime())
        time.sleep(1.0)
예제 #10
0
def dnfile(filename):
    os.chdir('c:\\windows\\system32\\drivers\\etc')
    try:
        ahk.start()
        ahk.ready()
    except:
        filename.write('running ahk.start or ready failed at %s\n' %
                       time.ctime())
        time.sleep(5.0)
    cmd = 'UrlDownloadToFile,https://autohotkey.com/download/2.0/AutoHotkey_2.0-a076-aace005.zip,0293293'
    try:
        returncode = ahk.execute(cmd)
    except:
        filename.write('url dntofile failed at %s\n' % time.ctime())
        time.sleep(5.0)
예제 #11
0
import ahk
import time
script = ahk.Script()
script.variable("text",
                str)  #set AHK variable that can be accessed with Python
ahk.execute("SetTitleMatchMode 2")
currLines = []
prevLines = []

while (True):
    #gpsStatus = ahk.execute("WinActivate, NovAtel")
    #if gpsStatus == True: #if GPS Window exists
    #	print "Exists!"
    #	messageStatus = ahk.execute("WinActivate, CONFIG - ASCII")
    #	if messageStatus == True: #if GPS ASCII coordinate window exists
    ahk.execute("WinGetText, text, CONFIG - ASCII")
    curr_text = script.text
    #print curr_text
    lines = curr_text.split('\n')
    for line in lines:
        if line not in prevLines:
            currLines.append(line)
            if line.find(
                    "#BESTPOS"
            ) != -1:  #if line has GPS coordinates, splice the string
                gpsCoords = line[line.find(';'):line.find("WGS")]
                gpsCoords = gpsCoords[gpsCoords.find("SINGLE") + 7:]
                gpsCoords = gpsCoords[:gpsCoords.rfind(',')]
                gpsCoords = gpsCoords[:gpsCoords.rfind(',')]
                gpsCoords = gpsCoords[:gpsCoords.rfind(',')]
                gpsCoords = gpsCoords[gpsCoords.find(',') + 1:]
예제 #12
0
put(e){
	global
	if(++i>100)
		i:=1
	q%i%:=e
}

#Persistent
gui,Show,x-1 y-1 w1 h1 NA,pyPortal_GUI
OnMessage(0x4a, "On_WM_COPYDATA")

i:=0
,n:=1000

settimer,debug,50
return
debug:
tooltip % q%i% "," i 
return
'''

ahk.execute(txt)

queue_ind = 0
queue_max = 1000
threading.Timer(1.0, check_ahk).start()

while 1:
    sleep(1)
예제 #13
0
def ahkExec(script):
    """Executes AutoHotKey Code"""
    script = replaceEgVars(script)
    ahk.start()
    ahk.ready()
    ahk.execute(str(script))
예제 #14
0
파일: hktest1.py 프로젝트: Xynnect/pyAHK
import ahk
ahk.start() # Ititializes a new script thread
ahk.ready() # Waits until status is True
ahk.execute('a := WinActive("Notepad")') # Sets a to the return value of WinActive
print ahk.get('a') # prints the HWND of the found window or 0x0 as a string
import ahk
import time
script = ahk.Script()
script.variable("text", str) #set AHK variable that can be accessed with Python
ahk.execute("SetTitleMatchMode 2") 
currLines = []
prevLines = []

while (True):
	#gpsStatus = ahk.execute("WinActivate, NovAtel")
	#if gpsStatus == True: #if GPS Window exists
	#	print "Exists!"
	#	messageStatus = ahk.execute("WinActivate, CONFIG - ASCII")
	#	if messageStatus == True: #if GPS ASCII coordinate window exists
	ahk.execute("WinGetText, text, CONFIG - ASCII")
	curr_text = script.text
	#print curr_text
	lines = curr_text.split('\n')
	for line in lines:
		if line not in prevLines:
			currLines.append(line)
			if line.find("#BESTPOS") != -1: #if line has GPS coordinates, splice the string
				gpsCoords = line[line.find(';'):line.find("WGS")]
				gpsCoords = gpsCoords[gpsCoords.find("SINGLE") + 7:]
				gpsCoords = gpsCoords[:gpsCoords.rfind(',')]
				gpsCoords = gpsCoords[:gpsCoords.rfind(',')]
				gpsCoords = gpsCoords[:gpsCoords.rfind(',')]
				gpsCoords = gpsCoords[gpsCoords.find(',')+1:]
				gpsCoords = gpsCoords[gpsCoords.find(',')+1:]				
				print gpsCoords #GPS coordinates in form "lat, lon"
			#if messageStatus == False:
예제 #16
0
import ahk

ahk.start()  # Ititializes a new script thread
ahk.ready()  # Waits until status is True
ahk.execute(
    'a := WinActive("Notepad")')  # Sets a to the return value of WinActive
print ahk.get('a')  # prints the HWND of the found window or 0x0 as a string
예제 #17
0
파일: ahkjam.py 프로젝트: kernow-ged/AHKjam
bpm = 60				# change this to whatever bpm you like
events = 300				# playback will consist of this many sound 'events' 
stay_back_forward = [0.4, 0.6, 1.0]    	# cumulative for the probabilities [0.4, 0.2, 0.4]
same_or_reroll_position = [0.6, 1.0]	# cumulative for the probabilities [0.6, 0.4]
same_or_reroll_duration = [0.5, 1.0]	# cumulative for the probabilities [0.5, 0.5]


qnote = 60.0/bpm
durations = [qnote * 2, qnote, qnote / 2, qnote / 4, qnote * 2 / 3, qnote * 2 / 5, qnote * 2 / 7, qnote * 4 / 9]
interval = durations[random.randint(0,7)]
position = random.randint(18, 251)     # where 18 is the leftmost end of the transport bar, and 251 the rightmost
keystroke = 'x'

ahk.start()				
ahk.ready() 				
ahk.execute('Esc::\nSend v\nExitApp')  		# 'safe word' / key is Esc
ahk.execute('SetMouseDelay, 0')
ahk.execute('SetKeyDelay, 0')
ahk.execute('WinActivate, ahk_class Winamp v1.x')
ahk.execute('Click 108,62')  		# clicks volume to 0%
ahk.execute('Send ' + keystroke)

for x in range(0, events):
	if random.random() > same_or_reroll_position[0]:
		position = random.randint(18, 251)
	if random.random() > same_or_reroll_duration[0]:
		interval = durations[random.randint(0,7)]
	p = random.random()
	if p < stay_back_forward[0]:
		keystroke = 'x'				# where 'x' is the keyboard shortcut for 'play' (on Winamp it restarts playing track)
	elif p < stay_back_forward[1]:
예제 #18
0
def site_download(page, destination):
    ahk.start()
    ahk.ready()
    ahk.execute("Send,^s")
    ahk.execute("WinWaitActive, Save As,,2")
    ahk.execute("WinActivate, Save As")
    
    save_as = "Send, " + destination + page
    save_as = save_as.encode('utf8')
    ahk.execute(save_as)
    ahk.execute("Send, {Enter}")
    ahk.execute("Send, {Enter}") 
예제 #19
0
import ahk

ahk.start() # Ititializes a new script thread
ahk.ready() # Waits until status is True

ahk.execute('send, 12345') # Sets a to the return value of WinActive
# print ahk.get('a') # prints the HWND of the found window or 0x0 as a string