Hotkey: Using ~LShift/LShift Up + function call Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hotkeyguy
Posts: 170
Joined: 11 Oct 2014, 12:22

Hotkey: Using ~LShift/LShift Up + function call

29 Nov 2021, 13:17

Hello,

how can I use Hotkey with KeyNames ~LShift/LShift Up and a function call as Label? And modifier Shift should be processed by the active app as usual.


Many thanks and greetings
hotkeyguy
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Hotkey: Using ~LShift/LShift Up + function call

29 Nov 2021, 13:50

What is an example of what you want to achieve?
hotkeyguy
Posts: 170
Joined: 11 Oct 2014, 12:22

Re: Hotkey: Using ~LShift/LShift Up + function call

29 Nov 2021, 16:02

...Wrong button, too fast...

Hello mikeyww,

I want to switch the mode of AHK-scripts depending of pressed modifier keys (Shift, Ctrl and Alt) and their combinations (e. g.Shift+Ctrl). The corresponing AHK GUI must change after any of the modifier keys is pressed. Thats means when I press Shift first, the mode is KB__Mod_Shift (first GUI change) and when I then press additionally Ctrl the mode is KB__Mod_ShiftCtrl (second GUI change). Because I want to change the GUIs dynamically, I can't use GetKeyState().
In more detail I want to differentiate between the left and right modifier keys, but that's the next step.

I have seen your code snippet, many thanks. After my comprehensive tests I think it's easier to use use Hotkey because I can disable/enable the hotkeys as needed. KeyWait blocks the other possible modifier keys.


Many thanks and greetings
hotkeyguy
Last edited by hotkeyguy on 29 Nov 2021, 16:26, edited 1 time in total.
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Hotkey: Using ~LShift/LShift Up + function call  Topic is solved

29 Nov 2021, 16:15

This hotkey routine will execute each time you press one of the hotkeys. The new key press will interrupt the previously running routine. It is just a demonstration. You can adjust it to meet your needs.

Code: Select all

~*LShift::
~*LCtrl::
mode := mode()
KeyWait, LShift
KeyWait, LCtrl
ToolTip, %mode%
Return

mode() {
 Return GetKeyState("LCtrl", "P") + 2 * GetKeyState("LShift", "P")
}
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Hotkey: Using ~LShift/LShift Up + function call

29 Nov 2021, 16:36

It looks like you are on your way to success. Instead of editing earlier posts in response to later ones, you can just put your new reply in a new reply. It makes the thread easier to follow.
hotkeyguy
Posts: 170
Joined: 11 Oct 2014, 12:22

Re: Hotkey: Using ~LShift/LShift Up + function call

29 Nov 2021, 16:50

Based on your example...

Code: Select all

~*LShift::
~*LCtrl::
  sMode := Mode()
  ToolTip, % "ModeDown (" sMode ")"
  KeyWait, LShift
  KeyWait, LCtrl
return

*LShift Up::
*LCtrl Up::
  sMode := Mode()
  ToolTip, % "ModeUp (" sMode ")"
  KeyWait, LShift
  KeyWait, LCtrl
return


Mode() {
 return GetKeyState("LCtrl", "P") + 2 * GetKeyState("LShift", "P")
}
...but I would really like to know how I can use Hotkey with ~LShift/LShift U!
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Hotkey: Using ~LShift/LShift Up + function call

29 Nov 2021, 16:55

From your earlier post, you have determined that using Hotkey is easier for you. You can enable or disable a routine by using a regular subroutine label. You can then use Hotkey as in the example.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Fredrik F, maxkill, RandomBoy, ShatterCoder and 342 guests