a hotkey links to another hotkey? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
surfactant
Posts: 99
Joined: 28 Jun 2019, 01:07

a hotkey links to another hotkey?

04 Jul 2021, 02:12

I have two scripts:

1.ahk

Code: Select all

LWin::^+a
2.ahk

Code: Select all

^+a::Send XXX
I hope pressing LWin gives XXX. How should I fix the codes?

Thank you for your help!
safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: a hotkey links to another hotkey?

04 Jul 2021, 02:43

You could use #InputLevel on your first script.

Code: Select all

#InputLevel, 1 ; The following hotkeys will have higher level.
LWin::^+a
#InputLevel, 0 ; To add hotkeys with normal level after this.
necomerx
Posts: 57
Joined: 01 Jan 2021, 09:09

Re: a hotkey links to another hotkey?

04 Jul 2021, 03:01

Hi, try this in on script:

Code: Select all

^+a::
Send, XXX
return
LWin::
SendInput, ^+a
return
surfactant
Posts: 99
Joined: 28 Jun 2019, 01:07

Re: a hotkey links to another hotkey?

04 Jul 2021, 03:05

@safetycar Thank you for your solution!

But it's odd what I got are inconsitent results when pressing LWin again and again:

XX
XX
xXX
xXX
XX
XX
xXX
XX
xXX
surfactant
Posts: 99
Joined: 28 Jun 2019, 01:07

Re: a hotkey links to another hotkey?

04 Jul 2021, 03:10

@necomerx

Code: Select all

^+a::
Send, XXX
return
LWin::
SendInput, ^+a
return
With your codes above, pressing LWin gives nothing. Thanks!
safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: a hotkey links to another hotkey?

04 Jul 2021, 03:34

surfactant wrote:
04 Jul 2021, 03:05
@safetycar Thank you for your solution!

But it's odd what I got are inconsitent results when pressing LWin again and again:

XX
XX
xXX
xXX
XX
XX
xXX
XX
xXX
It's making the Shift key stuck
I'm going to take a look at it.

I don't recommend you to keep using the code script like this, it's going to be annoying.
safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: a hotkey links to another hotkey?

04 Jul 2021, 03:47

I can't debug it now anymore.
It has started working properly by itself for me :crazy:
surfactant
Posts: 99
Joined: 28 Jun 2019, 01:07

Re: a hotkey links to another hotkey?

04 Jul 2021, 03:48

@safetycar

Yes, you are absolutely right ---- the practice should be avoided. But now I have an special situation and need to call a hotkey defined in another script.

Thanks a lot!
safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: a hotkey links to another hotkey?

04 Jul 2021, 03:50

I've found that this line at the top of both scripts make quite a big difference:

Code: Select all

SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
If your keys are still acting up because of the previous try pressing Ctrl and Shift, separately a couple of times each to try to release them.
necomerx
Posts: 57
Joined: 01 Jan 2021, 09:09

Re: a hotkey links to another hotkey?

04 Jul 2021, 04:00

surfactant wrote:
04 Jul 2021, 03:10
@necomerx

Code: Select all

^+a::
Send, XXX
return
LWin::
SendInput, ^+a
return
With your codes above, pressing LWin gives nothing. Thanks!
That's strange, it is working for me... Did you exit your first script and only run this one? Because if the two scripts using LWin are running the hotkey won't work.
surfactant
Posts: 99
Joined: 28 Jun 2019, 01:07

Re: a hotkey links to another hotkey?

04 Jul 2021, 04:18

@safetycar With the new statement added, the issue seems to persist, although slightly less frequently.

@necomerx If you press the hotkey for more times, it seems to disrupt the functions of Ctrl and Shift.

Thank you both!
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: a hotkey links to another hotkey?  Topic is solved

04 Jul 2021, 05:01

instead of "linking" hotkeys from one script with another's(and possibly have the keyboard hooks duke it out), PostMessage from one script to the other telling it which hotkey subroutine to invoke(and optionally with which parameters in case its a function)
surfactant
Posts: 99
Joined: 28 Jun 2019, 01:07

Re: a hotkey links to another hotkey?

04 Jul 2021, 07:08

@swagfag Passing an argument seems to be the right choice. Thank you!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: bobstoner289, Google [Bot], peter_ahk, Spawnova and 346 guests