Alt counts as pressed after using macro Topic is solved

Ask gaming related questions
Beta256692
Posts: 2
Joined: 11 Mar 2024, 19:41

Alt counts as pressed after using macro

Post by Beta256692 » 11 Mar 2024, 20:30

Hello there, I am new to AutoHotkey and am currently trying to set up macros to help me with my Java programming using AHK v2; however, I am running into an issue and also have some questions about AHK to see if I can simplify the macro.

First and foremost, the code I am having issues with is:

Code: Select all

#Requires AutoHotkey v2.0
SetKeyDelay(50)



; Setup File
Alt & Numpad0::
{
    Send("public class TEMP() {{}`n")
        Send("`t/* ------- ESTABLISH CLASS INSTANCE VARIABLES ------- */`n")
        Send("`n`n`n`n`n`n`n")

        Send("/* ------- CONSTRUCTORS ------- */`n")
        Send("`n`n`n`n`n`n`n")

        Send("/* ------- GETTERS ------- */`n")
        Send("`n`n`n`n`n`n`n")

        Send("/* ------- SETTERS ------- */`n")
        Send("`n`n`n`n`n`n`n")

        Send("/* ------- METHODS ------- */`n")
        Send("`n`n`n`n`n`n`n")

        Send("/* ------- HELPER METHODS / STATIC METHODS ------- */`n")
        Send("`n`n`n`n`n`n`n")

        Send("/* ------- TESTER METHOD ------- */`n")
            Send("`tpublic static void main(String[] args) {{}`n")
                Send("`t;`n")
            Send("`b{}}`n")
    Send("`b`b{}}")
}
Note: The code above is the entire file.


A.) My first issue is that after I run the macro my computer seems to think the alt key is being held down. I have tried running Send("{alt}") and Send("{alt up}") at the end of the macro but neither have worked. Because of this, I am unable to type or delete anything until I manually hit the alt key. Nothing too major, but it is annoying me quite a lot.



I also have a few questions.
1.) Is there any way for me to reduce the "`n" so I don't need to have 7 of them typed out to ensure 7 lines of space between my labels?
2.) I was having issues with send not outputting the correct values until I put in SetKeyDelay(50) at the top, but is 50 overkill to solve this issue? (Ex: "()" from the first send was occasionally sent as "90" and rarely a few characters would not be typed and then randomly rematerialize somewhere else after another few Send()s were run).
3.) I am currently using a Send() statement for each line of code and/or comment in my Java file template. Is there way way for me to condense this into one Send() without condensing all the strings into a single line (I still want to be able to easily read it)?

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

Re: Alt counts as pressed after using macro  Topic is solved

Post by boiler » 11 Mar 2024, 21:30

Try this. Not sure the intent of all your characters, especially the backspaces, so adjust as necessary.

Code: Select all

#Requires AutoHotkey v2.0
SetKeyDelay 50

!Numpad0:: {
	KeyWait 'Alt'
    SendEvent "
	(LTrim
		public class TEMP() {{}
        `t/* ------- ESTABLISH CLASS INSTANCE VARIABLES ------- */
        {Enter 7}
        /* ------- CONSTRUCTORS ------- */
        {Enter 7}
        /* ------- GETTERS ------- */
        {Enter 7}
        /* ------- SETTERS ------- */
        {Enter 7}
        /* ------- METHODS ------- */
        {Enter 7}
        /* ------- HELPER METHODS / STATIC METHODS ------- */
        {Enter 7}
        /* ------- TESTER METHOD ------- */
        `tpublic static void main(String[] args) {{}
        `t;
        `b{}}
    	`b`b{}}
	)"
}

Regular Send in v2 is Input mode, which isn't affected by KeyDelay. So either change the mode to Event or use SendEvent.

Beta256692
Posts: 2
Joined: 11 Mar 2024, 19:41

Re: Alt counts as pressed after using macro

Post by Beta256692 » 11 Mar 2024, 22:29

Thank you very much, @boiler. The code you have sent has covered every point I needed help with. :D

Post Reply

Return to “Gaming”