AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SingleInstance, Ignore and command line parameters?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
RobOtter



Joined: 30 Jan 2005
Posts: 125
Location: Darmstadt, Germany

PostPosted: Tue Dec 04, 2007 4:47 pm    Post subject: SingleInstance, Ignore and command line parameters? Reply with quote

Because of performance issues, I want to keep a script unreplaceable by using
Code:
#SingleInstance Ignore

I discovered that in this mode it seems not possible to receive command line parameters if the script is called again. Is there any way to get around this?
Thanks in advance,
Rob
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Tue Dec 04, 2007 5:26 pm    Post subject: Reply with quote

so you are telling it to not start the new script, but you do want the new script's parameters?

it would be better to either change how you are calling the script, or let the second script run, but if it detects another copy, IPC over the items you want, then close.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
[VxE]



Joined: 07 Oct 2006
Posts: 1125

PostPosted: Tue Dec 04, 2007 9:12 pm    Post subject: Reply with quote

Code:
#Singleinstance off
#persistent
SetTitleMatchMode 2
DetectHiddenWindows on
OnMessage(0x313, "CommandPass")
WinGet, id, list, %a_scriptname%
if id3
{
   ; Third Instance, user error: ignore.
   exitapp
   return
}
if id2
{
   ; Second Instance, submit parameters and desist
   PostMessage, 0x313, 403, %1%, , ahk_id %id1%
   exitapp
}
else if id1
{
   ; First Instance, initiate routines pending user direction
}
return
CommandPass(wParam, lParam, msg)
{
   ; Render new parameters and subsume
}

Here's an adaptation of one of my early scripts with the guts cut out. Of course, you would have to fill in the rest of the script, but you should get the idea. The WinGet command gets a list of all current processes with the same name as the script (with title match on mode 2, so be careful about using the script while editing it in notepad) then , if it detects itself as the second copy of the script, it notifies the first copy of the script via the "PostMessage" function. You'd have to do some tailoring to pass non-numeric parameters this way, but it's not difficult.

Basically, the above code can make different instances of a script perform dofferent actions.
_________________
My Home Thread
More Common Answers: 1. It's in the FAQ 2. Ternary ( ? : ) guide 3. Post code with [code][/code] tags
Back to top
View user's profile Send private message
RobOtter



Joined: 30 Jan 2005
Posts: 125
Location: Darmstadt, Germany

PostPosted: Wed Dec 05, 2007 9:01 am    Post subject: Reply with quote

engunneer wrote:
let the second script run, but if it detects another copy, IPC over the items you want, then close.

Sorry, I donŽt understand: what does IPC mean?

Thanks to you both for your efforts, but I would really like to avoid starting any second script since this will take a (little) while. I think IŽll explain my case in more detail:

I am using a MS keyboard with this @!#% F-Lock key and want to eliminate the alternate key binding of the function keys which is active by default. Since it is not possible at all to remap them to another key code but only to assign a program, I thought of writing a small script which only sends a key stroke (that corresponds to the function key that lies on the same key) and assign it to the alternate function key. Right now, my script looks like this and works quite well:
Code:
SendInput, {Blind}%1%


How smaller can it be? I compiled it as SendKey.exe and assign this command line to every alternate function key with the corresponding function key number:
"SendKey.exe {F1}"

So, for every press of an alternate function key, the script is loaded and executed. Sometimes loading the script takes a while (may be due to heavy use of the hard disk) and so the key stroke is sent with a noticable delay. This is why I would like to reuse an already running script and only pass the new parameters to it.
If you know of an alternate (better) way to accomplish the main task, I would really be thankful!
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Wed Dec 05, 2007 5:41 pm    Post subject: Reply with quote

IPC in this case refers to majkinetor's Interprocess communication module.

considering your circumstances, you may be interested in adapting the DDE server posted in the S&F section of the forum. That may help.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
RobOtter



Joined: 30 Jan 2005
Posts: 125
Location: Darmstadt, Germany

PostPosted: Thu Dec 06, 2007 5:13 am    Post subject: Reply with quote

DDE sounds like an interesting approach but I really have no clue how to send a DDE message from the command line - I think this is what I would have to do if I donŽt want to start a program at the press of a function key Question
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2558
Location: Australia, Qld

PostPosted: Thu Dec 06, 2007 8:32 am    Post subject: Reply with quote

RobOtter wrote:
DDE sounds like an interesting approach but I really have no clue how to send a DDE message from the command line - I think this is what I would have to do if I donŽt want to start a program at the press of a function key Question
DDE is suitable if you want Explorer to send messages to your script when the user executes a verb on a file (e.g. via double-click or the context menu.) However, file types must be registered (in the registry!) for this. You can manually initiate a DDE connection, but majkinetor's IPC module is generally much easier to use.

DDE Server (for single-instance file association) [std-lib]
(There's also a better solution than DDE, using COM, on pages 3 & 4. Look for "AutoHotkeyVerb".)


If the command-line args aren't simply file-names, I'd go with majkinetor's IPC module.


Can you assign your function keys to documents? For instance, you could create a file type ".ahkcmd" and register that with DDE or IDropTarget (aka "AutoHotkeyVerb".) Then create (empty) .ahkcmd files, like F1.ahkcmd. When the file is launched, Explorer should send its name to the running script, which can then interpret it as a command.
Back to top
View user's profile Send private message
RobOtter



Joined: 30 Jan 2005
Posts: 125
Location: Darmstadt, Germany

PostPosted: Fri Dec 07, 2007 12:09 pm    Post subject: Reply with quote

Quote:
Can you assign your function keys to documents? For instance, you could create a file type ".ahkcmd" and register that with DDE or IDropTarget (aka "AutoHotkeyVerb".) Then create (empty) .ahkcmd files, like F1.ahkcmd. When the file is launched, Explorer should send its name to the running script, which can then interpret it as a command.

Hm... Interesting idea: sending a key by assigning a file extension Cool

IŽll give a try at the weekend. If anything goes wrong, youŽll read me again Smile

Thanks for your suggestions,
Rob
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group