Combine two keys with a modifier Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Sweetins
Posts: 110
Joined: 02 Jul 2017, 13:22

Combine two keys with a modifier

21 Oct 2018, 03:49

I need to add alt to the combination of the left arrow key and the down or up arrow key and map it to a function.

Code: Select all

!Left & Up:: BS.SetBrightness(+1)

Code: Select all

!Left & Down:: BS.SetBrightness(-1)
The above approach doesn't work. Is there any work around?
User avatar
Scr1pter
Posts: 1272
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Combine two keys with a modifier

21 Oct 2018, 06:39

Yes, this is possible.

Basically you can set that while Alt is being pressed,
a value of a variable should get changed.
When releasing the key, the value should get set to default.

For example:
Alt pressed: mode = 1
Alt released: mode = 0

By using this method, you can easily use 3 key combinations.

You can try this:

Code: Select all

LAlt::
while GetKeyState("LAlt", "P") ; While left alt is being pressed:
{
  mode = 1 ; Set mode to 1 (ON)
} ; After left alt has been released::
mode = 0 ; Set mode to 0 (OFF)
return

#if mode = 1 ; If mode is 1 (ON):
Left & Up::
BS.SetBrightness(+1)
return

Left & Down::
BS.SetBrightness(-1)
return
Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Combine two keys with a modifier  Topic is solved

21 Oct 2018, 14:29

Code: Select all

#if GetKeyState("LAlt", "P")
Left & Up::BS.SetBrightness(+1)
Left & Down::BS.SetBrightness(-1)
Sweetins
Posts: 110
Joined: 02 Jul 2017, 13:22

Re: Combine two keys with a modifier

23 Oct 2018, 01:38

Thanks swagfag, it works just fine. :beer:
Scr1pter, your solution is not bad either.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, mikeyww and 279 guests