Using Hotkey If, With EvilC TapHoldManager Library - autohotkey

Lately I have been using Autohotkey to help me get past my left hands injury and the pain I get when I "push it" by reaching out for keys, especially, when my other hand is on the mouse
I recently had this brilliant idea that will let me eliminate reaching out for keys, by using a keypad instead of a full sized keyboard.
My idea is to use a VIM style hotkey\editing (The Linux\text editing tool) design.
when I tap NumpadSub, then first tap of NumpadMult should perform a special action. After this first tap of NumpadMult future taps should perform the default windows function, as if no AHK scripts were running.
The thing is, to make up for the small number of keys available, I want to use EvilC's TapHoldManager library to achieve this. I have spent the past few days increasing my knowledge of this library.
Using THIS post and u\ExpiredDebitCard answer HERE I came up with this:
#include <TapHoldManger>
THMLeader:= new TapHoldManager(200,400,2)
THMLeader.Add("NumpadSub", Func("LeaderKey__NumpadSub"))
THMLeader.Add("NumPadMult", Func("LeaderKey__NumPadMult"))
LeaderKey__NumpadSub(isHold, taps, state)
{
if (taps == 1)
if (isHold == 0)
{
Tooltip, THMLeader Tap x1
TestFlag := 1
}
else
{
if (state)
{
Tooltip, THMLeader Hold x1
}
; else
; {
; }
}
}
LeaderKey__NumPadMult(isHold, taps, state)
{
if (taps == 1)
if (isHold == 0)
{
Tooltip, LeaderKey__NumPadMult Tap x1
}
else
{
if (state)
{
Tooltip, LeaderKey__NumPadMult Hold x1
}
; else
; {
; }
}
}
TestFlag := 1
Hotkey If,TestFlag == 1
;Hotkey If,(TestFlag == 1)
THMSubKey:=New TapHoldManager(200,400,2)
THMSubKey.Add("NumpadMult", Func("SubKey__NumPadMult"))
#If
SubKey__NumPadMult(isHold,taps,state)
{
if (taps == 1)
if (isHold == 0)
{
Tooltip, SubKey__NumPadMult Tap x1
TestFlag := 0
}
else
{
if (state)
{
Tooltip, SubKey__NumPadMult Hold x1
TestFlag := 0
}
; else
; {
; }
}
}
My intention with the above code is that, SubKey__NumPadMult code block should only ever be active if variable TestFlag is set to 1. Only single tap of NumpadSub can set TestFlag to 1. so
So in short,
A single tap of NumpadSub followed by NumpadMult will print SubKey__NumPadMult Tap x1.
A single tap of NumpadMult NOT preceded by a tap of NumpadSub will print LeaderKey__NumPadMult Tap x1
I am having issues with getting Hotkey If,TestFlag == 1 to work though. Running the above code gives me a runtime error:
Error: Parameter #2 must match an existing #If expression.
Changing it around like. Hotkey If,(TestFlag == 1) has not helped either.
What am I doing wrong here? I have tried many things, nothing seems to be giving in. Any help or ideas would be great.
Thanks for any help

Related

AHK v2 mouse clicking loop

global toggleVar := false
>^j::
{
global toggleVar :=! toggleVar
}
if (WinActive("Warframe") and toggleVar = true)
{
while (GetKeyState("LButton"))
{
Click
Sleep 250
}
}
I am absolute noob in autohotkey, installed it today, also got scared by a bunch of viruses. Anyways, I wanted to have a toggle variable and when I'm in a game I want to hold down LMB and it will continue clicking for me. But it does nothing and I have no idea why.
#HotIf WinActive("Warframe")
>^j::
{
static toggle := 0
HotIf 'WinActive("Warframe")' ; change the hotkey context for Hotkey function
Hotkey "LButton", SpamClick, (toggle := !toggle) ? "On" : "Off" ; enable or disable lbutton hotkey
SpamClick(ThisHotkey) {
while GetKeyState("LButton", "P") {
Click
Sleep 250
}
}
}
#HotIf
Apparently this is how it's supposed to be done, it worked for me. Thanks to "plankoe" from reddit.

combining hotkeys

I'm trying to make an autoclicker in autohotkey but can't get it to work.
I have some knowledge about autohotkey but it is not very much:
<^LButton::
Loop
{
SetMouseDelay 0.001
Click
If(GetKeyState("LButton","P")=0)
Break
}
It works with <^LButton as hotkey, but not <^nLButton.
Therefore I need help with hotkey-combinations.
I get the errorcode:
Line Text: <^nLButtonSuspend
Error: This line does not contain a recognized action.
If you want to combinate Three keys as a Hotkey.
Click the Keys : [Ctrl] + [n] + [Lbutton] = Do a Action.
You can Try this:
example1.ahk
;#notrayicon
#SingleInstance force
^n::
GetKeyState, state, Lbutton
if state = D
{
Loop
{
send a
;SetMouseDelay 0.001
;Click
If(GetKeyState("LButton","P")=0)
Break
}
} else {
send b ;this codeline is only so that you can test it out in notepad. - you can remove this
}
Return
esc::exitapp
note : It is not perfect but the answer is close to your Question.

Best way to count length of UITextInput text value in Swift?

I have two UITextInput controls that I want to count the number of characters in.
For context, I have two inputs: one for email address and one for password. I also have a “Login” button. The button is inactive by default, but as soon as at least one character is entered into both inputs, I’ll programatically enable the button. This is to prevent login attempts until the user has entered a value in both fields.
So far, I’m using this approach:
if count(emailInput.text) > 0 && count(passwordInput.text) > 0 {
// Enable button
} else {
// Disable button
}
Is using the count() function acceptable? Or is there a better way? As I recall there are some gotchas with checking the length of strings in iOS/Swift.
For me personally the following code has worked fine in past.
if (!emailInput.text.isEmpty && !passwordInput.text.isEmpty) {
// enable button
} else {
// disable button
}
if((emailInput.text!.characters.count) > 0 && (passwordInput.text!.characters.count) > 0) {
// Enable button
} else {
// Disable button
}
Swift 4
emailInput.text!.count
Swift 2
self.emailInput.text!.characters.count
but if you need to do something more elegant you can create an extension like this
Nowadays, after putting count directly on text property my guess is to use this directly without extension, but if you like to isolate this sort of things, go ahead!.
extension UITextField {
var count:Int {
get{
return emailInput.text?.count ?? 0
}
}
}

How to have one key toggle between two functions using AHK

How would I go about creating a hotkey in AHK that runs one function the first time it is pressed and another one the second time it is pressed. I'm trying to emulate an on/off scenario.
Can it be done and if so how?
Something like this pseudo code is what I'm looking for:
#space::toggleit()
toggleit()
{
if (last time it was pressed, functionA was run)
run functionB
else
run functionA
}
I'm using AHK version 1.1.19.01
Try using AutoHotkey's hotkey-command:
hotkey, #space, functionA
return
functionA:
hotkey, #space, functionB
msgbox, A
return
functionB:
hotkey, #space, functionA
msgbox, B
return
If you'd want to toggle only between functionA and "do nothing", you can use the following:
hotkey, #space, functionA, toggle
return
functionA:
msgbox, A
return
I found a solution. Putting it here for other's benefit:
#space::tog()
tog()
{
static togstate = 0
if (togstate = 1)
{
msgbox ON
togstate = 0
}
else
{
msgbox OFF
togstate = 1
}
}
An easy way is to use a variable:
setting := false
toggleit()
{
if setting
run functionB
else
run functionA
setting := !setting
}

Why aren't these two functions toggling on click event?

I'm trying to toggle two functions. When user clicks the pause button, the input fields are disabled, the label is text is changed to grey and the button changes to a different image. I thought I could use .toggle(), but I can't get the two functions to work either -- only the first one function runs (pauseEmailChannel();), not both on toggle click. I found the even/odd clicks detection script here on SO, but that is not "toggling" these two functions on the click event. My code may be ugly code, but I'm still learning and wanted to show how I am thinking -- right or wrong. At any rate, can someone give me a solution to how to do this? I didn't think it would be too difficult but I'm stuck. Thanks.
HTML
jQuery
$(".btn_pause").click(function(){
var count = 0;
count++;
//even odd click detect
var isEven = function(num) {
return (num % 2 === 0) ? true : false;
};
// on odd clicks do this
if (isEven(count) === false) {
pauseEmailChannel();
}
// on even clicks do this
else if (isEven(count) === true) {
restoreEmailChannel();
}
});
// when user clicks pause button - gray out/disable
function pauseEmailChannel(){
$("#channel-email").css("color", "#b1b1b1");
$("#notify-via-email").attr("disabled", true);
$("#pause-email").removeClass("btn_pause").addClass("btn_disable-pause");
}
// when user clicks cancel button - restore default
function restoreEmailChannel(){
$("#channel-email").css("color", "#000000");
$("#notify-email").attr("disabled", false);
$("#pause-email").removeClass("disable-pause").addClass("btn_pause");
$("input[value='email']").removeClass("btn_disable-remove").addClass("btn_remove");
}
try this code. It should work fine, except that I could make a mistake when it is even and when odd, but that should be easy to fix.
$(".btn_pause").click(function(){
var oddClick = $(this).data("oddClick");
$(this).data("oddClick", !oddClick);
if(oddClick) {
pauseEmailChannel();
}
else {
restoreEmailChannel();
}
});
The count variable is initialized and set to 0 every time .btn_pause is clicked. You need to move the variable to a higher scope.
For example,
$(".btn_pause").each(function(){
var count = 0;
$(this).click(function(){
count++;
...
});
});
In this way count is initialized only once and it is accessible in the click event handler.
As an alternative way you can also use:
$(".btn_pause").each(function(){
var count = 0;
$(this).click(function(){
[restoreEmailChannel, pauseEmailChannel][count = 1 - count]();
});
});
If the previous construct was too abstract, a more verbose one will look like this:
$(".btn_pause").each(function(){
/* Current element in the array to be executed */
var count = 0;
/* An array with references to Functions */
var fn = [pauseEmailChannel, restoreEmailChannel];
$(this).click(function(){
/* Get Function from the array and execute it */
fn[count]();
/* Calculate next array element to be executed.
* Notice this expression will make "count" loop between the values 0 and 1.
*/
count = 1 - count;
});
});