Using "&" Without Blocking?

Get help with using AutoHotkey and its commands and hotkeys
hemsith14_
Posts: 15
Joined: 07 Nov 2020, 08:37

Using "&" Without Blocking?

18 Nov 2020, 04:03

Hey

Is it possible to send something like "Alt & b" without blocking hotkeys like "^!b"?

Thanks for your help!

Edit: the "Alt &" is necessary for one of them and can't be changed to "!".
Last edited by hemsith14_ on 18 Nov 2020, 07:50, edited 1 time in total.
Rohwedder
Posts: 3818
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Using "&" Without Blocking?

18 Nov 2020, 04:09

Hallo,
try:

Code: Select all

Send, !b
Why should this block any Hotkey?
hemsith14_
Posts: 15
Joined: 07 Nov 2020, 08:37

Re: Using "&" Without Blocking?

18 Nov 2020, 06:54

Once I send ^!b in a script that contains Alt & b, the ^!b hotkey triggers the Alt & b one. This is what I'm trying to prevent.

I need them to be 2 sepereate hotkeys.
User avatar
boiler
Posts: 6653
Joined: 21 Dec 2014, 02:44

Re: Using "&" Without Blocking?

18 Nov 2020, 07:19

When you say you send Alt & b, do you mean you are sending them using the Send command? Or you just have two separate hotkeys? Are you using !b as Rohwedder suggested? Can you post the exact lines from your script that are causing a problem?
User avatar
mikeyww
Posts: 4191
Joined: 09 Sep 2014, 18:38

Re: Using "&" Without Blocking?

18 Nov 2020, 07:25

Code: Select all

!b::Send x
^!b::Send y
Or:

Code: Select all

Alt & b::Send % GetKeyState("Ctrl") ? "x" : "y"
Or:

Code: Select all

^!b::Send y

#If !GetKeyState("Ctrl")
Alt & b::Send x
hemsith14_
Posts: 15
Joined: 07 Nov 2020, 08:37

Re: Using "&" Without Blocking?

18 Nov 2020, 07:38

Code: Select all

; Test

Alt & b::
Send, hello world
Returb

^!b::
Send, 12345
Return
Currently when I press Ctrl Alt b, it sends hello world, which isn't the right hotkey. I need to understand how to get them to co-exist. This is just a test code BTW.

Sorry if I wasn't clear enough, let me know if it's understandable.
Last edited by hemsith14_ on 18 Nov 2020, 07:39, edited 1 time in total.
User avatar
mikeyww
Posts: 4191
Joined: 09 Sep 2014, 18:38

Re: Using "&" Without Blocking?

18 Nov 2020, 07:39

I provided three methods.

Code: Select all

!b::Send hello world
^!b::Send 12345
hemsith14_
Posts: 15
Joined: 07 Nov 2020, 08:37

Re: Using "&" Without Blocking?

18 Nov 2020, 07:43

I can't use "!" as Alt in one of them since the "Alt &" is necessary for one of my hotkeys.

In the best case scenario, I'd like to add something to "Alt & b" in order to get it out of the way of ^!b. But still, the & function is necessary in Alt b.
User avatar
mikeyww
Posts: 4191
Joined: 09 Sep 2014, 18:38

Re: Using "&" Without Blocking?

18 Nov 2020, 07:52

All three methods work, so you have a choice.

Code: Select all

^!b::Send 12345

#If !GetKeyState("Ctrl")
Alt & b::Send hello world
hemsith14_
Posts: 15
Joined: 07 Nov 2020, 08:37

Re: Using "&" Without Blocking?

18 Nov 2020, 07:54

Could you briefly explain why would it work?
What is the "!" doing before the "GetKeyState"?

Thanks!
User avatar
mikeyww
Posts: 4191
Joined: 09 Sep 2014, 18:38

Re: Using "&" Without Blocking?

18 Nov 2020, 07:56

1. Have you tested it?

2. ! means "Not". If CTRL is not pressed, then all subsequent lines will apply.

#If enables the use of context-sensitive hotkeys and hotstrings.
hemsith14_
Posts: 15
Joined: 07 Nov 2020, 08:37

Re: Using "&" Without Blocking?

18 Nov 2020, 07:59

1. Not yet, I'll be able to do it soon.

2. I see. What if I'll have more shortcuts that using other modifiers and Alt+b in them? Would I have to insert more "ifs"?

Furthermore, it is possible to fix it so Alt & b would be the same as "!b" in terms of its activation (so it would be limited just to these 2 charecters)?
User avatar
mikeyww
Posts: 4191
Joined: 09 Sep 2014, 18:38

Re: Using "&" Without Blocking?

18 Nov 2020, 08:05

Code: Select all

^!b::Send 12345
!+b::Send abc

#If !GetKeyState("Ctrl") && !GetKeyState("Shift")
Alt & b::Send hello world
You haven't fully explained your needs for Alt & b, which differs from !b. No, they are not the same, but you have your choice to use either of them.
hemsith14_
Posts: 15
Joined: 07 Nov 2020, 08:37

Re: Using "&" Without Blocking?

18 Nov 2020, 08:08

So can I add && and just put all of the modifers there?
User avatar
mikeyww
Posts: 4191
Joined: 09 Sep 2014, 18:38

Re: Using "&" Without Blocking?

18 Nov 2020, 08:20

Yes, but there aren't many more modifiers left for you!

You can actually use any sort of condition or expression on the #If line. The documentation is below.

https://www.autohotkey.com/docs/commands/_If.htm

When you have more time, you can try these various things to see what works for you.
hemsith14_
Posts: 15
Joined: 07 Nov 2020, 08:37

Re: Using "&" Without Blocking?

18 Nov 2020, 09:36

And what if I'm using the #if already in order to detact a certain window? Would it interrupt it if I put another if inside of it?

Example:

Code: Select all

#if WinActive ; define window

#If !GetKeyState("Ctrl")
Alt & b::Send hello world
#If ; stops get key state if?

# if ; stops defining window ?
In case it's not possible to do it like that, how should I do it?
User avatar
mikeyww
Posts: 4191
Joined: 09 Sep 2014, 18:38

Re: Using "&" Without Blocking?

18 Nov 2020, 09:44

As explained in the documentation, which I recommend reading, one statement at a time applies, but as I mentioned, you can combine expressions in any combination that you need.

Code: Select all

#If !GetKeyState("Ctrl") && WinActive("ahk_exe notepad.exe")
Alt & b::Send hello world
#If
#If and #IfWin are also mutually exclusive; that is, only the most recent #If or #IfWin will be in effect.
There are other ways to organize the conditionals to meet your needs. You can have just one conditional statement, and then check for the other condition within the hotkey routine. My other examples above show other possibilities, such as not using the #If directive at all.

Give it a whirl, and see what works.
Christoff
Posts: 1
Joined: 15 Jun 2020, 09:03
GitHub: Christoffel16

Re: Using "&" Without Blocking?

18 Nov 2020, 23:32

Code: Select all

Alt & b::gosub % GetKeyState("Ctrl") ? "ctrl_alt_b" : "alt_b"
return

alt_b:
MsgBox, You pressed Alt+b
return

ctrl_alt_b:
MsgBox, You pressed Ctrl+Alt+b
return
I did a little tweak for one of the solution above, maybe this will help
hemsith14_
Posts: 15
Joined: 07 Nov 2020, 08:37

Re: Using "&" Without Blocking?

19 Nov 2020, 00:47

Thank you very much

Return to “Ask For Help”

Who is online

Users browsing this forum: ashamefuldog, Bing [Bot], Freshman, TAC109 and 46 guests