Running script on startup without hotkey Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dakitt
Posts: 3
Joined: 09 Oct 2017, 01:13

Running script on startup without hotkey

Post by dakitt » 09 Oct 2017, 01:26

Hey there,

I ran into a beautiful piece of code from @Lexikos, that enables me to toggle mouse acceleration (or pointer precision) by using a hotkey. Works flawlessly.
BUT Logitech driver causes Windows to reset the setting automatically on every startup.

Now is it possible to launch a script without a hotkey by putting a shortcut to the compiled .exe in the autostart folder? If yes, which piece of code do I have to use for this?

Mouse acceleration should be turned ON, maybe with a little MsgBox telling me that it's on now.

Thank you guys in advance!!

My code:

Code: Select all

WhatIsIt?:
    SPI_GETMOUSE(accel, low, high)
    MsgBox, , , Mouse acceleration settings`n  accel:`t%accel%`n  low:`t%low%`n  high:`t%high%, 1
return

^NumpadAdd::    ; Enable acceleration.
^NumpadSub::    ; Disable acceleration.
    SPI_SETMOUSE(A_ThisHotkey="^NumpadAdd") ; i.e. 1 if ^NumpadAdd, 0 otherwise.
    gosub WhatIsIt?
return

^NumpadEnter::  ; Toggle acceleration.
    if SPI_GETMOUSE(accel)
        SPI_SETMOUSE(!accel)
    ;else an error occurred.
    gosub WhatIsIt?
return


; Get mouse acceleration level and low/high thresholds.
; Returns true on success and false on failure.
SPI_GETMOUSE(ByRef accel, ByRef low="", ByRef high="")
{
    VarSetCapacity(vValue, 12)
    if !DllCall("SystemParametersInfo", "uint", 3, "uint", 0, "uint", &vValue, "uint", 0)
        return false ; Fail.
    low := NumGet(vValue, 0)
    high := NumGet(vValue, 4)
    accel := NumGet(vValue, 8)
    return true
}

; Set mouse acceleration level and low/high thresholds.
; Supplies standard default values for low/high if omitted.
; fWinIni:  0 or one of the following values:
;           1 to update the user profile
;           2 to notify applications
;           3 to do both.
; Returns true on success and false on failure.
SPI_SETMOUSE(accel, low="", high="", fWinIni=0)
{
    VarSetCapacity(vValue, 12)
    , NumPut(accel
    , NumPut(high!="" ? high : accel ? 10 : 0
    , NumPut(low!="" ? low : accel ? 6 : 0, vValue)))
    return 0!=DllCall("SystemParametersInfo", "uint", 4, "uint", 0, "uint", &vValue, "uint", 0)
}
Last edited by dakitt on 09 Oct 2017, 07:01, edited 1 time in total.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Running script on startup without hotkey

Post by BoBo » 09 Oct 2017, 01:39

Now it it possible to launch a script without a hotkey by putting the .exe in the autostart folder? If yes, which piece of code do I have to use for this?
Create a shortcut to your (compiled) script and drop it to the autostart folder. That should do the trick.

dakitt
Posts: 3
Joined: 09 Oct 2017, 01:13

Re: Running script on startup without hotkey

Post by dakitt » 09 Oct 2017, 01:55

But isn't the script waiting for the hotkey trigger?

User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Running script on startup without hotkey  Topic is solved

Post by boiler » 09 Oct 2017, 06:40

It looks like adding this line to the top of the script would start it in accelerated mode:
SPI_SETMOUSE(1)
And it's already set up to show a message box saying it's on after that.

Also, you don't have to compile the script (unless there's something specific about this script that only works when compiled). You can put a shortcut to the .ahk file in your startup directory.

dakitt
Posts: 3
Joined: 09 Oct 2017, 01:13

Re: Running script on startup without hotkey

Post by dakitt » 09 Oct 2017, 06:59

Thank you, I will try this!

So Windows can run .ahk-scripts by itself? (I don't have AHK installed due to lack of privileges, I only use compiled .EXEs)

User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Running script on startup without hotkey

Post by boiler » 09 Oct 2017, 07:15

No, you're correct. If you cannot install AHK, then you will need to use the compiled .exe file and place a shortcut to that file in your Windows startup folder.

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Running script on startup without hotkey

Post by LAPIII » 23 Oct 2021, 03:22

boiler wrote: No, you're correct. If you cannot install AHK, then you will need to use the compiled .exe file and place a shortcut to that file in your Windows startup folder.
So I can put an AHK file in the Windows startup folder?

User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Running script on startup without hotkey

Post by boiler » 23 Oct 2021, 06:22

LAPIII wrote: So I can put an AHK file in the Windows startup folder?
You can, but it’s better to put a shortcut to the AHK file in the Windows startup folder rather than putting your original AHK file or a duplicate of it in the folder.

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Running script on startup without hotkey

Post by LAPIII » 21 Dec 2021, 15:00

boiler wrote:
23 Oct 2021, 06:22
You can, but it’s better to put a shortcut to the AHK file in the Windows startup folder rather than putting your original AHK file or a duplicate of it in the folder.
Why?

User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Running script on startup without hotkey

Post by boiler » 21 Dec 2021, 16:21

Because your startup folder should always contain only shortcuts. As another example, if you wanted Outlook to start every time, you wouldn’t move its .exe to the startup folder. For one thing, it wouldn’t have its surrounding support files. The shortcut allows it to run from its installed location where it has its supporting files. The same thing for AHK scripts. If your script has any supporting files, it would find them as expected without you needing to copy them all to that folder.

Even if the script has no supporting files, having only the one real file and using a shortcut is better because then you can just change the original file if modifications are necessary and the shortcut automatically uses the most up-to-date version.

You might ask why not keep the only version of the file in the startup folder. I suppose you could do that, but that is a bad habit to get into for file organization reasons and because then you would have a mix of some located there while others aren’t for the above reasons. Just do the right thing every time.

Post Reply

Return to “Ask for Help (v1)”