Hold down Alt key

Ask gaming related questions (AHK v1.1 and older)
abellos
Posts: 10
Joined: 08 Jul 2018, 03:00

Hold down Alt key

Post by abellos » 06 Mar 2024, 14:37

Hello guys,
i need a script for a game to hold down the Alt key, i wrote this script

Code: Select all

5::
Toggle := !Toggle

If not Toggle {
	Send {Alt up}
	TrayTip "alt up", "alt up"
} else {
	
    Send {Alt down}
    TrayTip "alt down", "alt down"
    
}
it hold the key pressed, but i cant stop the pressed alt. I think when alt is pressed it expect another key to do a combination.
There is some solution to deactivate the alt pressed?

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

Re: Hold down Alt key

Post by boiler » 07 Mar 2024, 06:18

You can either add the hotkey with Alt so that either triggers it:

Code: Select all

5::
!5::
Toggle := !Toggle
...

Or just add the wildcard modifier to your hotkey:

Code: Select all

*5::

abellos
Posts: 10
Joined: 08 Jul 2018, 03:00

Re: Hold down Alt key

Post by abellos » 07 Mar 2024, 14:04

Thank you, now i see the tray tip alt up also with you help, but when i repress 5 to unlock Alt key, is see "alt up" message but it still pressed, i need to press one time the Alt key phisically on keyboard. U can try open a notepad and press f or m u see that open the menu
This is my entire script

Code: Select all

#SingleInstance Force
#MaxThreadsPerHotkey 2
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; only run this script if Diablo window is active
;#IfWinActive, Diablo II: Resurrected

; If the script is not elevated, relaunch as administrator and kill current instance:

full_command_line := DllCall("GetCommandLine", "str")

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try ; leads to having the script re-launching itself as administrator
    {
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
        else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}

5::
!5::
Toggle := !Toggle

If not Toggle {
	;Send {Alt up}
	Send {Alt}
	TrayTip "alt up", "alt up"
} else {
	
    Send {Alt down}
	TrayTip "alt down", "alt down"
}
there is something that interfere?
ty for the help

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

Re: Hold down Alt key

Post by boiler » 07 Mar 2024, 15:11

You may be able to address this via #MenuMaskKey. I have never really done anything with it, though, so I can't advise from experience with it.

Post Reply

Return to “Gaming Help (v1)”