Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Pass parameters to AutoHotkey script


  • Please log in to reply
10 replies to this topic
Mithondriel
  • Guests
  • Last active:
  • Joined: --
Hi all, i am trying to make an aplication with Visual Basic 6.0 and AutoHotKey. I want to make an Autohotkey script that lets me send parameters to him, and run a part of the code script acording the parameter sended.
I read the the part "Passing Command Line Parameters to a Script" from the Autohotkey's Manual but it doen't serv me. Because is a command line parameters on execute time and i want to pass parameters at the same time of the script is running. In this way i can "say" what i want to my autohotkey script do through Visual Basic.

For example, I send trough Visual Basic the word "E-mail", then the Script:

If var = "E-Mail"
{
code
}

Lot of thanks

DevX
  • Members
  • 43 posts
  • Last active: Jan 12 2011 06:44 PM
  • Joined: 07 Jan 2009
Medium difficulty task.

Either have to use the clipboard to transfer the data, or use window messages.

I believe window messages would be the best solution, as it will not interrupt anything of the user, and wont rely on the clipboard issues you may run into (clipboard times out every now and then).

I don't know the relevant code for Visual Basic, but in ahk its
PostMessage, 0x8888, , %MouseCoords%, , ahk_id %CurWinHwnd%
And in the ahk script you would do
OnMessage(0x8888, "UnPause")

UnPause(wParam, lParam, msg, hwnd)
{
MsgBox % "hi"
}

Lookup OnMessage() in autohotkey help files.

camerb
  • Moderators
  • 573 posts
  • Last active: Sep 14 2015 03:32 PM
  • Joined: 19 Mar 2009
Sure sounds like you're launching an AHK using VB...

This will pull your first command line param into the variable named "var" that you specified...

var=%1%
If var = "E-Mail" 
{ 
code 
}

Aren't you glad that I didn't put an annoying gif here?

The same
  • Guests
  • Last active:
  • Joined: --
Yes i tryed this way. But i want to send parameters after the script is running, not at execute time.
And if this way is posible i don't know how is the command ms-dos console.

Thanks a lot !!!

The same
  • Guests
  • Last active:
  • Joined: --
This is my ahk script:
---------------------------------------------------------------------------------

OnMessage(0x0C, "READTHE")

READTHE(wParam, lParam)
{
Send {F9 down}{F9 up}
Sleep, 100
MouseClick, left, 285, 330,2
Sleep, 100
MouseClick, left, 285, 330,2
Sleep, 100
}

---------------------------------------------------------------------------------

And through Visual Basic:

Dim l As Long, s As String
l = FindWindowEx(FindWindow("Autohotkey", vbNullString), 0, vbNullString, vbNullString)

s = "some"

SendMessage l, WM_SETTEXT, 0, ByVal s

But it still not working.
Thanks all.

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
You have the right idea with SendMessage, however you may want to take a look at the WM_COPYDATA message, rather than WM_SETTEXT.

The same
  • Guests
  • Last active:
  • Joined: --
I get the same problem.

Any idea?

Thanks !!!

The same
  • Guests
  • Last active:
  • Joined: --
Here is the solution: (thanks to RaptorX in freenode chat irc)

ClipWait, 10


OnClipboardChange:
ClipSaved := Clipboard
msgbox % clipsaved

if ClipSaved contains keyword ; If it contains "keyword" string
{
CODE
}
return

A lot of thanks to RaptorX, a good person and with a lot of patience. xD.
Bye, and thanks to all.

kiwijunglist
  • Members
  • 61 posts
  • Last active: Aug 14 2013 05:56 AM
  • Joined: 26 May 2009

I don't like using the clipboard so I have used files to transfer information

Loop
{
if FileExist("c:\temp\1654842454545.txt")
{
FileRead, varCom, c:\temp\1654842454545.txt
FileDelete, c:\temp\1654842454545.txt
msgbox % varCom
}
Sleep 2000
}

Not sure if that is best way, but that is what I have done in the past.  Could probably use setTimer as well here.



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

how do you use SetTimer with this?:

I don't like using the clipboard so I have used files to transfer information

Loop
{
if FileExist("c:\temp\1654842454545.txt")
{
FileRead, varCom, c:\temp\1654842454545.txt
FileDelete, c:\temp\1654842454545.txt
msgbox % varCom
}
Sleep 2000
}

Not sure if that is best way, but that is what I have done in the past.  Could probably use setTimer as well here.



kiwijunglist
  • Members
  • 61 posts
  • Last active: Aug 14 2013 05:56 AM
  • Joined: 26 May 2009
#persistent
#singleinstance force
setTimer, CheckMsgs, 1000 ;Check for new messages once per second.
 
 
CheckMsgs:
if FileExist("C:\temp\kiwijunglist.message")
{
FileRead, Str, C:\temp\kiwijunglist.message
FileDelete, C:\temp\kiwijunglist.message
msgbox % "You have a message: " Str
}
Return