addition of one line of code to an existing AHK Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Sebastian42
Posts: 28
Joined: 10 Mar 2019, 23:42

addition of one line of code to an existing AHK

20 Mar 2019, 06:04

I need to activate NUMLOCK before running an AHK - I expect that it means adding one line of code to the existing AHK. I have no idea what that code would be, and hoped I could be given it holus bolus by this forum, without having to learn/research 'all' the mechanics of Autohotkey.
AviationGuy
Posts: 188
Joined: 17 Jan 2019, 10:13

Re: addition of one line of code to an existing AHK

20 Mar 2019, 06:24

If one of the 'NumLock' keys isn't needed to activate the script you can put SetNumLockState, On above your script to activate the NumLock keys.

Code: Select all

SetNumLockState, On
Msgbox NumLock activated
Check the docs here: https://autohotkey.com/docs/commands/SetNumScrollCapsLockState.htm
Sebastian42
Posts: 28
Joined: 10 Mar 2019, 23:42

Re: addition of one line of code to an existing AHK

20 Mar 2019, 17:30

Thank you so much.
I added your code at the top of the AHK, below the last line starting with #,
but 'Code: Select All' kept triggering an error message saying 'does not contain a recognised action' for various permutations of those three words.
When I left it out completely, the AHK created an icon in the systray/notification area, but the NUMLOCK LED did not light up, and pressing the numlock keys did not achieve the desired effect. Can you help further ?
AviationGuy
Posts: 188
Joined: 17 Jan 2019, 10:13

Re: addition of one line of code to an existing AHK

20 Mar 2019, 17:41

Sure, can you post your script?
gregster
Posts: 9114
Joined: 30 Sep 2013, 06:48

Re: addition of one line of code to an existing AHK

20 Mar 2019, 23:50

Look again, CODE: SELECT ALL is not part of the AHK code that you should add, but it is part of the code box that contains and nicely formats the AHK code - you can actually click Select All and it will select all code in the code box:

Select All.png
Select All.png (5.28 KiB) Viewed 1828 times

PS: I think that your general understanding of AHK could benefit from looking at the basics, for example, the beginner's tutorial.
AviationGuy
Posts: 188
Joined: 17 Jan 2019, 10:13

Re: addition of one line of code to an existing AHK

21 Mar 2019, 03:00

gregster wrote:
20 Mar 2019, 23:50
Look again, CODE: SELECT ALL is not part of the AHK code that you should add...
Ohh, that is what you meant. No, CODE: SELECT ALL isn't what you should put in your own script as @gregster already mentioned :)
Sebastian42
Posts: 28
Joined: 10 Mar 2019, 23:42

Re: addition of one line of code to an existing AHK  Topic is solved

21 Mar 2019, 06:26

I'm happy and grateful to report that without getting a degree in AutoHotKeys, I was able to achieve my aim, by just inserting "SetNumLockState, On" at the very top of the code.

Rather than post [which I am sure to do incorrectly] the code you asked for, I'll give you the 'heading' in the script.

;
; AutoHotkey Version: 1.0.48.5
/*
** TaskbarMove.ahk - Move the taskbar (startbar) around the screen with Hotkeys
**
** Updated: Sat, Nov 19, 2011 --- 11/19/11, 4:19:19pm EST
** Keywords: move taskbar, move startbar, move task bar, move start bar
** Location: r.secsrv.net/AutoHotkey/Scripts/TaskbarMove
**
** Author: JSLover - r.secsrv.net/JSLover - r.secsrv.net/JSLoverAHK
** Web: http jslover.secsrv.net /AutoHotkey/Scripts/TaskbarMove.ahk Broken Link for safety
*/

I had to do a lot of trial and error to discover where the correct place was to insert the "SetNumLockState, On", but that is now behind me.
Once again many thanks from someone reluctant to spend more of his life studying unintelligible code.
AviationGuy
Posts: 188
Joined: 17 Jan 2019, 10:13

Re: addition of one line of code to an existing AHK

21 Mar 2019, 06:52

My scripts usually have the same structure.
First the lines I think most of the scripts should start with.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
 ;#Warn  ; Enable warnings to assist with detecting common errors. (Remove the ; in front of the # when you want to enable this)
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability. ;*[TestFileStudio]
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force  ; Allows script to run again when it's already running
After these, I recommend placing the other commands that will apply to your script.
So things like the 'SetNumLockState', 'SetCapsLockState' or 'includes' when needed.

Code: Select all

#Include MyFunc1.ahk ; just some random functions/library's
#Include MyFunc2.ahk
#Include ahkLib.ahk
SetNumLockState, On
Underneath these you can start with your script like so
Spoiler
PS. Keep in mind that 'SetNumLockState' can be used in different ways. When 'SetNumLockState' isn't used as a hotkey, like in the example above, it will always trigger when you start the script.
But when you use 'SetNumLockState' within a hotkey like so

Code: Select all

^m::
SetNumLockState, On
return
It will only trigger when the hotkey ctrl+m is pressed.

This was just some extra info. Hopefully, it will help you in the future.
Sebastian42
Posts: 28
Joined: 10 Mar 2019, 23:42

AHK opening in text editor instead of 'doing a job'.

22 Mar 2019, 06:40

I was going to make a new thread - because the substance is different - but since my experimenting with the above appears to precede my new difficulties, I will post here, and you can always move it to a new thread if you think that is better.
For years, to efficiently DOUBLE-save excel spreadsheets to two separate locations, I have been using an AHK in a batch file, along with a copy process, and then another AHK to close a folder. That worked well for a about dozen spreadsheets. But now, starting the spreadsheet saving process, may trigger the display of the AHK in a text editor, rather than perform the function. It is not entirely consistent, not all the spreadsheet saving batch files misbehave like that, and the ones that do, don't do so every time. The anomaly appeared after I successfully tested an AHK to move the taskbar around. That taskbar-moving AHK is not usually active/activated/launched/enabled.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: PercyPierce, peter_ahk and 107 guests