Help modifing or creating new script in V2 Please Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
AutoHotkey-User
Posts: 4
Joined: 27 May 2023, 18:37

Help modifing or creating new script in V2 Please

Post by AutoHotkey-User » 27 May 2023, 20:50

Hello,

At the moment i am using AutoHotkey Version 2, script to open-launch Firefox as my current example below.

#!f::Run "C:\Program Files\Mozilla Firefox\firefox.exe"

What i really would like to change, or a new script to do is.

Using windows key # and Alt ! Both pressed same time, (As in my current script) then press F key and again press F key
(Twice within say 2 seconds, as a time example)

Hope i make sense in what i am trying to achieve, as a script if possible?

If so, it would be wonderful if someone could please help with, example script.

Thank you in advanced.


AutoHotkey-User
Posts: 4
Joined: 27 May 2023, 18:37

Re: Help modifing or creating new script in V2 Please

Post by AutoHotkey-User » 01 Jun 2023, 00:54

Hello,

Thank you Rohwedder, for your reply and help with posting an example link to look at.
To be honest I have no idea on how to make a scrip from that example. I am a newbie to AutoHotkey and trying to get more understanding on making scripts.

I have a rethink and will try to explain below.

Now I am using AutoHotkey Version 2, script to launch Firefox browser, Notepad++, and quite a few other apps as example.

To launch Firefox in my current script
#!f::Run "C:\Program Files\Mozilla Firefox\firefox.exe"

This works but what I would really like is a script that can work as above but where f is in the script, it would be...as below.

Example to launch Firefox, hold down Windows key and Alt keys together then click M key and then click the F key.

Example for Notepad++ would be, hold down Windows key and Alt keys together then click N key and then click the P key.

Is a script like this possible please. Can you, or someone with more knowledge on writing scripts help in making a script that would achieve this.


Then from the example, I can add more programs to the script that I would like to launch.

Thank you in advance for anyone that can help.

Rohwedder
Posts: 7550
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Help modifing or creating new script in V2 Please

Post by Rohwedder » 01 Jun 2023, 03:00

Hallo,
Windows key should be avoided! Otherwise Windows could do funny things.
Therefore, hold down left control and left alt key and type your 2 letters. Try:

Code: Select all

<^LAlt::
<!LCtrl::
Input, Keys, ML2T4 ;2 Keys in < 4 seconds
KeyWait, LAlt
KeyWait, LCtrl
Switch, Keys
{
Case "mf":Run "C:\Program Files\Mozilla Firefox\firefox.exe"
Case "np":Run "C:\Program Files\notepad++.exe"
Default:ComObjCreate("SAPI.SpVoice").Speak("you typed " SubStr(Keys,1,1) " " SubStr(Keys,0))		
}
Return

AutoHotkey-User
Posts: 4
Joined: 27 May 2023, 18:37

Re: Help modifing or creating new script in V2 Please

Post by AutoHotkey-User » 02 Jun 2023, 01:32

Hello,

Thank you Rohwedder, for your reply and help. Very much appreciated.

This script works a treat. If I may ask, Is there a way to make this script work with AutoHotkey Version 2. As this is what I use on my main PC.

Currently this script needs AutoHotkey version 1, which I would have to install along side with version 2.

I have read where Version 2 has many advantages, and version 1 is now deprecated.

So if Version 2 is better going forward, can this script be changed to work with AHK Version 2 ?

Rohwedder, thanks again for your time and help.

Rohwedder
Posts: 7550
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Help modifing or creating new script in V2 Please  Topic is solved

Post by Rohwedder » 02 Jun 2023, 04:24

Sorry, I often get the dialects mixed up.

Code: Select all

#Requires AutoHotkey v2.0
<^LAlt::
<!LCtrl::
{
    ih := InputHook("ML2T4") ;2 Keys in < 4 seconds
    ih.Start(), ih.Wait(), KeyWait("LAlt"), KeyWait("LCtrl")    
    Switch Keys:= ih.Input
    {
    Case "mf":Run "C:\Program Files\Mozilla Firefox\firefox.exe"
    Case "np":Run "C:\Program Files\notepad++.exe"
    Default:ComObject("SAPI.SpVoice").Speak("you typed " SubStr(Keys,1,1) " " SubStr(Keys,-1)) 
    }
}

AutoHotkey-User
Posts: 4
Joined: 27 May 2023, 18:37

Re: Help modifing or creating new script in V2 Please

Post by AutoHotkey-User » 02 Jun 2023, 18:34

Hello Rohwedder,

You really have given me something much better to work with.

Much appreciated for all your help.

Danke ;)

Post Reply

Return to “Ask for Help (v2)”