Button on second click

Get help with using AutoHotkey and its commands and hotkeys
Houzuki
Posts: 9
Joined: 13 May 2016, 16:20

Button on second click

20 Mar 2018, 17:17

Hi, I need help with a code where i for example press the C button once, but when i press it another time it presses the P button
so its like c:: c
but on the second c click is like c:: p
dilof
Posts: 4
Joined: 20 Mar 2018, 08:07

Re: Button on second click

20 Mar 2018, 17:23

Code: [Select all] [Download] GeSHi © Codebox Plus

z::
toggle := !toggle
if toggle
SendInput {c}
else
SendInput {p}
return
swagfag
Posts: 236
Joined: 11 Jan 2017, 17:59

Re: Button on second click

20 Mar 2018, 18:10

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
Cuadrix
Posts: 138
Joined: 07 May 2017, 08:26

Re: Button on second click

20 Mar 2018, 19:31

Something like this?

Code: [Select all] [Download] GeSHi © Codebox Plus

lastShift := 0

$c::
if ((A_TickCount - lastShift) <= 250)
SendInput, p
else
SendInput, c
lastShift := A_TickCount
return
Last edited by Cuadrix on 21 Mar 2018, 19:10, edited 1 time in total.
Aɴᴅ ᴛᴏᴅᴀʏs ᴡɪɴɴᴇʀ ᴏꜰ ᴛʜᴇ ᴛɪᴛʟᴇ "Mᴀsᴛᴇʀ" ɪs...
User avatar
evilC
Posts: 4028
Joined: 27 Feb 2014, 12:30

Re: Button on second click

21 Mar 2018, 13:10

My TapHoldManager library will let you detect when a key is pressed any number of times, and also supports long-press, tap-and-press etc.
User avatar
divanebaba
Posts: 603
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Button on second click

21 Mar 2018, 15:21

dilof wrote:

Code: [Select all] [Download] GeSHi © Codebox Plus

z::
toggle := !toggle
if toggle
SendInput {c}
else
SendInput {p}
return
Nice solution, dilof, for learning and teaching, but not exactly desired solution. :mrgreen: :mrgreen:
Try this:

Code: [Select all] [Download] GeSHi © Codebox Plus

$c::
toggle := !toggle
if (toggle)
SendInput c
else
SendInput p
return

[Starklichtbirne IQ >> 250!!] Dank deutscher Lehrerempfehlung, nur Süperdepp und Hartz4-Bezieher, statt Abitürient und Einkommensbezieher.
[Strong light bulb IQ >> 250!!] Thanks to german teacher's recommendation, willful and welfare recipient, instead of high school graduate and moneymaker.

Entering high school for foreign children is not prohibited in GERMANY, it's only made nearly impossible by government.
Virtually the only way - visiting high school abroad.
wolf_II
Posts: 1804
Joined: 08 Feb 2015, 20:55

Re: Button on second click

21 Mar 2018, 16:22

Also try this one-liner:

Code: [Select all] [Download] GeSHi © Codebox Plus

$c:: SendInput, % (Flag := Not Flag) ? "c" : "p"
I hope that helps.
User avatar
Cuadrix
Posts: 138
Joined: 07 May 2017, 08:26

Re: Button on second click

21 Mar 2018, 19:11

divanebaba wrote:
dilof wrote:

Code: [Select all] [Download] GeSHi © Codebox Plus

z::
toggle := !toggle
if toggle
SendInput {c}
else
SendInput {p}
return
Nice solution, dilof, for learning and teaching, but not exactly desired solution. :mrgreen: :mrgreen:
Try this:

Code: [Select all] [Download] GeSHi © Codebox Plus

$c::
toggle := !toggle
if (toggle)
SendInput c
else
SendInput p
return

Damn it, made the same mistake :headwall:
Aɴᴅ ᴛᴏᴅᴀʏs ᴡɪɴɴᴇʀ ᴏꜰ ᴛʜᴇ ᴛɪᴛʟᴇ "Mᴀsᴛᴇʀ" ɪs...

Return to “Ask For Help”

Who is online

Users browsing this forum: djclinton18, Rohwedder, way2000 and 38 guests