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
Button on second click
Re: Button on second click
Code: Select all
z::
toggle := !toggle
if toggle
SendInput {c}
else
SendInput {p}
return
Re: Button on second click
Code: Select all
#NoEnv
#WinActivateForce
#SingleInstance, Force
#MaxThreadsPerHotkey 2
SendMode, Input
SetBatchLines, -1
SetTitleMatchMode, 2
SetWorkingDir, %A_ScriptDir%
class Robot {
shouldSendAlternate := false
sendAlternate(key := "") {
RegExMatch(A_ThisHotkey, "(\w+)", thisHotkey)
key := (this.shouldSendAlternate := !this.shouldSendAlternate) ? thisHotkey : key
Send, {%key%}
return
}
}
robot := new Robot()
$x::robot.sendAlternate("p")
z::ExitApp
Re: Button on second click
Something like this?
Code: Select all
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.
Re: Button on second click
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.
- divanebaba
- Posts: 805
- Joined: 20 Dec 2016, 03:53
- Location: Diaspora
Re: Button on second click
Nice solution, dilof, for learning and teaching, but not exactly desired solution.dilof wrote:Code: Select all
z:: toggle := !toggle if toggle SendInput {c} else SendInput {p} return
Try this:
Code: Select all
$c::
toggle := !toggle
if (toggle)
SendInput c
else
SendInput p
return
Einfach nur ein toller Typ.
Re: Button on second click
Also try this one-liner:
I hope that helps.
Code: Select all
$c:: SendInput, % (Flag := Not Flag) ? "c" : "p"
Re: Button on second click
Damn it, made the same mistakedivanebaba wrote:Nice solution, dilof, for learning and teaching, but not exactly desired solution.dilof wrote:Code: Select all
z:: toggle := !toggle if toggle SendInput {c} else SendInput {p} return
Try this:Code: Select all
$c:: toggle := !toggle if (toggle) SendInput c else SendInput p return
Who is online
Users browsing this forum: Google [Bot], Mannaia666 and 417 guests