mod toggling and meny questions

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rwh531
Posts: 8
Joined: 03 Feb 2023, 02:56

mod toggling and meny questions

Post by rwh531 » 03 Feb 2023, 05:51

Trying to make my Lbutton-Mbutton-Rbutton toggle the up/down position of modifier ctrl/alt/shift or maybe even the FN key so I can bind the side buttons on my mmo mouse to say 1-9 then use ctrl/shift to increase the functionality of the mouse and reduce keyboard dependency

for example (one of many methods ive tried

Code: Select all

~Rbutton down::send % getkeystate("Shift","p") ? "{Rbutton down}" : "{Shift down}"
+Rbutton up::send {Rbutton up}" : "{Shift up}"  "I need to be able to let go of the Shift button itself as it's programmed into a side button using the mouses own software and prevents me from using my thumb to click others
Also been toying with ahk ability to make menus and having problems for example (also is it possible to add to set 1-9 as hotkeys for menu items "only when the menu itself is active"
and can each menuitem perform multiple commands such as opening multiple applications or launch multiple tabs/windows of chrome maybe even to different web addresses or even side by side (trying my best to learn just what kind of power Ahk has. anyway this is my test script and the current problems i am experiencing with it.

Code: Select all

; Create the popup menu by adding some items to it.
Menu, MyMenu, Add, Item1, MenuHandler1
Menu, MyMenu, Add, Item2, MenuHandler2
Menu, MyMenu, Add  ; Add a separator line.
return 

MenuHandler1: 
Send:: #V "   "doesnt work" but if I reference a custom hotkey like below it does (what am i doing wrong"
+2::Send #v (works)

MenuHandler2: (works but it refuses to insert the @)
^F1::Send [email protected] (the 

+Mbutton::Menu, MyMenu, Show  ; i.e. press the Win-Z hotkey to show the menu.
[Mod edit: [code][/code] tags added.]

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: mod toggling and meny questions

Post by mikeyww » 03 Feb 2023, 06:24

Welcome to this AutoHotkey forum!

When you run your script and see an error message, if you do not understand the message, you can post a screenshot of it. Although Up is a hotkey modifier, Down is not a hotkey modifier. Without Up, a down-key is inferred. In the AHK documentation, you can check the syntax for both GetKeyState and ternary operators. As noted there, P assesses whether you are physically pressing the key. Since the ternary operator has three operands, it has two intervening symbols.

Here is a remap. I define toggle differently, but what you wrote appears to be more like a remap. If you are new to AHK, I recommend using its current version. Nonetheless, I posted with the older version here.

Code: Select all

#Requires AutoHotkey v1.1.33
; #Requires AutoHotkey v2.0
RButton::Shift
From your use of Send::, it looks like you may want to take a step back and read some of the introductory documentation about how to create a hotkey. A hotkey is not an AutoHotkey command, but Send is an AutoHotkey command. The intro shows you how to create a hotkey subroutine. This starts with a hotkey and then has all of the commands that should execute when the hotkey is triggered. You can have as many commands there as you like. A subroutine would not include a hotkey definition as you have written it, but it can have multiple commands.

The bottom line is that you can't throw together ideas that deviate from AHK's syntax. You have to use what is available. Fortunately, the documentation includes an example for every command (e.g., Send), so if you model the examples closely, you should be in good shape.

If you send an uppercase letter, AHK will manage Shift on your behalf, so use caution there, and send using the letter case that you really mean.

Another suggestion is to get one short script working before expanding the script and creating more scripts that do not work, adding multiple hotkeys and subroutines, etc. If the short version fails, the long version will most likely fail, and it's easier to debug a shorter script.

Code: Select all

#Requires AutoHotkey v1.1.33
Menu do, Add, 1 - 123, 123 ; Press the leading digit as a keyboard shortcut
Menu do, Add, 2 - Clipboard history, ClipHistory
Gosub F3

F3::Menu do, Show ; F3 = Show the menu

123:
Send 123
Return ; This command ends a subroutine

ClipHistory:
Send #v
SoundBeep 1500
Return
Last edited by mikeyww on 03 Feb 2023, 06:50, edited 2 times in total.

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: mod toggling and meny questions

Post by DuckingQuack » 03 Feb 2023, 06:43

Hello!
I am also fairly new to AHK and I noticed that you are using AHKv1. As it has recently become “deprecated” due to the “official” release of AHKv2, I suggest learning v2 instead of learning v1. But support for v1 isn’t going anywhere, so it’s really just a matter of preference.

As for the first question about using lb, mb, rb to toggle a modifier, the custom hotkey page has a section regarding using custom combinations that uses & with spaces to link the keys together. I’m pretty sure this will NOT let you slap three in one combination, therefore an if statement would be needed to link the result to the third button.
https://www.autohotkey.com/docs/v1/Hotkeys.htm#combo

For the next question prosed, I would like to point you to another use of & to underline the first character of a button to be used as its shortcut. Requires alt to be pressed with the underlined character, so may not fit your needs.
https://www.autohotkey.com/docs/v1/lib/GuiControls.htm#Button
Alternatively, you could use a single hotkey to open a gui that shows a list of actions associated with 0-9 and while that gui is active those hotkeys are active due to a (v1)#If or (v2)#HotIf restriction.
https://www.autohotkey.com/docs/v1/lib/_If.htm

As for your last and infinitely more complex question, your menu selections will do what ever you program to do. If you’re capable of creating functioning script that launches specific programs and opens specific web pages, then it’s a breeze to use that script as a subroutine that is activated by a hotkey. The run command will help you in those endeavors.
https://www.autohotkey.com/docs/v1/lib/Run.htm

I wish you great success!
Last edited by DuckingQuack on 03 Feb 2023, 07:24, edited 2 times in total.
Best of Luck,
The Duck

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

Re: mod toggling and meny questions

Post by boiler » 03 Feb 2023, 07:17

DuckingQuack wrote: As it has recently become “deprecated” due to the “official” release of AHKv2, I suggest learning v2 instead of learning v1. But support for v1 isn’t going anywhere, so it’s really just a matter of preference.
I would add another reason to choose v2: Perhaps the biggest improvement of v2 is its use of expressions throughout as opposed to the dual syntax of expressions and legacy/command syntax of v1. In my view, the dual syntax of v1 is easily the cause of the most frustration and difficulty for beginners learning AHK v1, which would be avoided entirely by using v2.

DuckingQuack wrote: As for the first question about using lb, mb, rb to toggle a modifier, the custom hotkey page has a section regarding using custom combinations that uses & with spaces to link the keys together. I’m pretty sure this will NOT let you slap three in one combination, therefore an if statement would be needed to link the result to the third button.
https://www.autohotkey.com/docs/v1/Hotkeys.htm#combo
Just so OP doesn’t get sent down an unnecessary rabbit hole of trying to not only implement a custom combination hotkey but also tying a third key to it, I believe the intent here was to tie each of the those three mouse buttons to one keyboard key, as the attempt at mapping RButton to Shift indicates, as opposed to using all three buttons simultaneously.

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: mod toggling and meny questions

Post by DuckingQuack » 03 Feb 2023, 07:21

boiler wrote:
03 Feb 2023, 07:17
Just so OP doesn’t get sent down an unnecessary rabbit hole of trying to not only implement a custom combination hotkey but also tying a third key to it, I believe the intent here was to tie each of the those three mouse buttons to one keyboard key, as the attempt at mapping RButton to Shift indicates, as opposed to using all three buttons simultaneously.
Ah, good point, that was a total misunderstanding on my part. Thank you.
Best of Luck,
The Duck

rwh531
Posts: 8
Joined: 03 Feb 2023, 02:56

Re: mod toggling and meny questions

Post by rwh531 » 06 Feb 2023, 03:55

boiler wrote:
03 Feb 2023, 07:17
DuckingQuack wrote: As it has recently become “deprecated” due to the “official” release of AHKv2, I suggest learning v2 instead of learning v1. But support for v1 isn’t going anywhere, so it’s really just a matter of preference.
I would add another reason to choose v2: Perhaps the biggest improvement of v2 is its use of expressions throughout as opposed to the dual syntax of expressions and legacy/command syntax of v1. In my view, the dual syntax of v1 is easily the cause of the most frustration and difficulty for beginners learning AHK v1, which would be avoided entirely by using v2.

DuckingQuack wrote: As for the first question about using lb, mb, rb to toggle a modifier, the custom hotkey page has a section regarding using custom combinations that uses & with spaces to link the keys together. I’m pretty sure this will NOT let you slap three in one combination, therefore an if statement would be needed to link the result to the third button.
https://www.autohotkey.com/docs/v1/Hotkeys.htm#combo
Just so OP doesn’t get sent down an unnecessary rabbit hole of trying to not only implement a custom combination hotkey but also tying a third key to it, I believe the intent here was to tie each of the those three mouse buttons to one keyboard key, as the attempt at mapping RButton to Shift indicates, as opposed to using all three buttons simultaneously.
I downloaded it shortly after making the initial post and while i have read the documentation that came with v1 multiple times I've always found it far more intuitive to learn by seeing the scripts of others and altering them for my needs. learning how they cant be used by trial and error and v2 seems to completely wipe the slate clean, also noticed it seemed to autocompile into an exe which I have no clue how to read or alter after creation. as I found out after trying to convert a v1 script

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

Re: mod toggling and meny questions

Post by boiler » 06 Feb 2023, 04:19

rwh531 wrote: also noticed it seemed to autocompile into an exe which I have no clue how to read or alter after creation.
Huh? When does it do that? Even if you are compiling it, it shouldn’t be removing the .ahk file. It should be adding a .exe file. But explain what is happening when you see it “autocompile.” What action triggers that? And the .ahk file is no longer there?

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: mod toggling and meny questions

Post by DuckingQuack » 06 Feb 2023, 06:56

rwh531 wrote:
06 Feb 2023, 03:55
I downloaded it shortly after making the initial post and while i have read the documentation that came with v1 multiple times I've always found it far more intuitive to learn by seeing the scripts of others and altering them for my needs. learning how they cant be used by trial and error and v2 seems to completely wipe the slate clean
I totally agree with this sentiment as it has always been my opinion (everyone’s got one) that AHKv1 felt like the coding language for people who didn’t code. It is much easier to make super basic scripts in v1 than in v2. And you’re also right that there is basically no transition from v1 to v2 in terms of applying what you already know to the new syntax, you really do ‘wipe the slate clean’ and it sucks. AHKv2 is a totally different language and there’s good reason for it. Primarily for the fact that as you progressed into more complex scripts with v1, you had to learn a different and more complex syntax and juggle multiple syntaxes in one script. All while knowing when and where to apply which one whereas in v2 it uses the same (albeit the more complex) syntax all the time which the documentation makes poor references to with hardly any examples. So yeah, if you plan to stay in the kiddie pool, then AHKv1 is the perfect temperature, stay in that pool… because the v2 pool is cold, and it will be until more people have moved over and there’s more examples online to reference and adopt.

I’ve used AHKv1 for nearly 18 years but never did anything more complicated than send and sleep in a loop. Only recently have I decided to challenge myself by taking the training wheels off and learning more about the language by downloading v2. It was a coincidence that I decided that two weeks before the official release of v2 because I wasn’t even aware it wasn’t “released” yet. In just a month I’ve been able to learn enough to take a script I wrote before v2 from about 65 lines to only 15. On top of that, I also eliminated all the small annoyances my script had because of sleep locking the script and send going only to the active window which prevented using this in a multi-box situation.

Before any coders jump down my throat explaining how much more simple and elegant and easier to read and etc… I get it, that’s because you’re a coder. But for a non-coder, starting a line with the command is more intuitive and easier to throw basic scripts together. There is no readability issues when you’re not making a several thousand line script. In fact, if you’re primarily using commands as most basic scripts focus on, then readability is actually increased.

And damn it all, in v2, if I can’t figure out where variables are at in the lines of code… at least in v1 all I had to do was find % symbols!

So stick with v1 if you’re staying simple, but if you ever plan to go deeper, you’ll basically be learning v2 while juggling v1 at the same time… so why not just use v2 at that point?
Best of Luck,
The Duck

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

Re: mod toggling and meny questions

Post by boiler » 06 Feb 2023, 08:26

DuckingQuack wrote: …whereas in v2 it uses the same (albeit the more complex) syntax all the time which the documentation makes poor references to with hardly any examples.
So examples at the bottom of the documentation page for each function (just like for v1) is “hardly any examples”? I’m thinking you couldn’t even tell which set of documentation has more examples without doing a count.

DuckingQuack wrote: And damn it all, in v2, if I can’t figure out where variables are at in the lines of code… at least in v1 all I had to do was find % symbols!
They’re the ones without quotes around them. Quoted text = literal string. Unquoted text = variable.

Is that more complex or just different that v1? : Percent signs around text = variable. No percent signs = literal string.

Your opinion is your opinion, and you are of course welcome to it.. Just pointing out some things so people who are currently unaware don’t take your opinions as facts and be scared off without warrant.

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: mod toggling and meny questions

Post by DuckingQuack » 06 Feb 2023, 09:26

@boiler I only have one decent example on hand of how the reference documents need better examples, I guarantee there are more, but this is a good one. That being, where on the gui.control page does it explain or provide an example of the syntax for referencing a gui control? It says “Mygui.control” and provides “MyGui.OnEvent()” as an example but where exactly am I supposed to gather that the syntax is “MyGui[‘BtnName’].OnEvent()”??
Best of Luck,
The Duck

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: mod toggling and meny questions

Post by mikeyww » 06 Feb 2023, 10:06

The following thread provides some of the relevant information.

viewtopic.php?f=82&t=113551

rwh531
Posts: 8
Joined: 03 Feb 2023, 02:56

Re: mod toggling and meny questions

Post by rwh531 » 18 Feb 2023, 04:07

boiler wrote:
06 Feb 2023, 08:26
DuckingQuack wrote: …whereas in v2 it uses the same (albeit the more complex) syntax all the time which the documentation makes poor references to with hardly any examples.
So examples at the bottom of the documentation page for each function (just like for v1) is “hardly any examples”? I’m thinking you couldn’t even tell which set of documentation has more examples without doing a count.
[Mod edit: Fixed quite tags.]


What i meant was larger complex examples for instance lets say I am stuck using simplistic commands

For example what if I want on screen text telling me what modifier keys are being held down
What if i want my middle mouse button to open a menu that allows me to change the state of capslock or numlock, and skip to the next track in my music playlist or god forbid toggle the down/up positions of modifier keys.

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: mod toggling and meny questions

Post by mikeyww » 18 Feb 2023, 06:25

You would build your script as a series of steps, just as would be done with any programming language. There are some different approaches to how people do that. If you read the documentation, you can learn and know the steps, so that you can assemble them. An alternative or addition is to search the forum, Web, books, etc. to find similar examples, and adapt them. The forum here has not only the help boards but also a board of scripts and functions that others have assembled and tested. Examining other people's code is a great way to learn about those "building blocks", so that you can assemble them in new ways that meet your needs. The examples provided in the documentation serve as a starting point to understand how a specific, individual command or function is used.

Post Reply

Return to “Ask for Help (v1)”