How to send a key only on double-tap? - keyboard-shortcuts

I know I can use
F1::Return
to disable the F1 key. But I would like to be able to still use it by simply double-tapping. However, when I try
$F1::
if (A_PriorHotkey <> F1 or A_TimeSincePriorHotkey > 400) {
KeyWait, F1
Return
}
Send, {F1}
(based on this post), the first press of F1 passes through while all following ones (including double-taps) are completely ignored.

Check your quotation marks...
$F1::
if (A_PriorHotkey <> "$F1" or A_TimeSincePriorHotkey > 400) {
KeyWait, F1
Return
}
Send, {F1}

Related

Error - Unexpected } at the end of While Loop

I'm using while true loop to constantly check run this script. After adding the if expression with whitelist ahk gives an error about unexpected } at the end of code. As far as I know there should be }.
Using Loop command gives the same error.
Removing the problematic } at the end causes the code running in background but not doing anything.
;Setup
Sleep, 1000
whiteList = "none"
;Main Loop
While True
{
siteName = YouTube
WinGetActiveTitle, tabName
Sleep, 10000
if tabName = %whiteList%{
Continue
}
;If current website is Youtube, ask if am I supposted to be here
if InStr(tabName, siteName){
Sleep, 10000
MsgBox, 292, Reality Check, Should you do this?
IfMsgBox, Yes
{
whiteList = tabName
}
;Close tab in mozilla
else
{
WinActivate, %tabName%
Sleep, 10
Send ^w
}
}
}
Code is unfinished, It should run in background and when the user is using YouTube fore some time it should ask him whether is he supposted to watch Youtube.
If he clicks yes, the program should ignore that specific page.
Else it should close it.
The % around the whiteList-var shouldn't be there. When I wrote it like below it seems to work:
if tabName = whiteList
Continue
Also the whiteList = tabName will just assign the string "tabName" to whiteList. Use whiteList := tabName for assigning, and if var1 = var2 for comparison.

AutoHotkey: Similar function like ClipWait for "Select All"

Does AutoHotkey have anything similar to "ClipWait" for "Ctrl+A" / "Select All".
Or is there a possibility to get such a function somehow ?
Would this be sufficient?
^b::
send ^a
selectionWait()
msgbox, All has been selected
return
selectionWait() {
clipboardSave := clipboardAll
loop {
send ^c
if(clipboard != clipboardSave)
if(clipboard != "")
break
}
clipboard := clipboardSave
}
ctrl+c IS fired before everything is selected, but this is on purpose. the action will be repeated until the clipboard contents have changed, and the clipboard will be reset to the previous value afterwards
I had the same problem when selecting many rows from a network database.
The “Select All” command didn't have time to complete, hence making
Copy & ClipWait useless,
Here's the beautiful fix:
Loop
{
Send, ^a
Send, ^c
ClipWait, 1
if (!ErrorLevel)
break
}
Or like this if you want to limit the wait to 5 seconds:
Loop, 5
{
Send, ^a
Send, ^c
ClipWait, 1
if (!ErrorLevel)
break
}

AHK: Different hotkeys via sequences with repeating keys

Ok my code has the following which works:
^m::Send M text{enter}
Return
^s::Send S text{enter}
Return
^t::Send T text{enter}
Return
Now I want to be able to add something like the following (this way it doesn't work):
^m & ^t:: Send M and T text{enter}
Return
^m & ^s:: Send M and S text{enter}
Return
^t & ^s:: Send T and S text{enter}
Return
I want AHK to take all three sequences like Ctrl+S does one thing and Ctrl+M does another but Ctrl+S+M does a different third action.
There is a similar post to this here: AutoHotKey key SEQUENCE, not just single-key hotkey
If you don't find a fitting solution, you might want to try the workaround which I've been using.
Note: the following does not include any hotkey triggers like ^m::, the problem is being solved with the hotkey-command and fitting label names, which actually look like a hotkey trigger (^m:)
hotkey, ^m, ^m, On
hotkey, ^t, ^m, On
return
^m_and_^t: ; will also be called from ^t & ^m
Send M and T text{enter}
triggered = true
return
^m_and_^s:
Send M and S text{enter}
triggered = true
return
^t_and_^s:
Send T and S text {enter}
triggered = true
return
^m:
triggered = false
hotkey, ^t, ^m_and_^t, On
hotkey, ^s, ^m_and_^s, On
loop
{
getkeystate, isDown, m, P
if isDown = U
break
}
hotkey, ^t, ^t, On
hotkey, ^s, ^m_and_^s, Off ; -> ^s will keep its natural function
if triggered = false
{
Send M text{enter}
}
return
^t:
triggered = false
hotkey, ^s, ^t_and_^s, On
hotkey, ^m, ^m_and_^t, On
loop
{
getkeystate, isDown, t, P
if isDown = U
break
}
hotkey, ^m, ^m, On
hotkey, ^s, ^m_and_^s, Off ; -> ^s will keep its natural function
if triggered = false
{
Send T text{enter}
}
return

How to capture "#" and "#" key pressed - Silverlight Textbox Keyup Event

I wrote below code for capturing "#" and "#" pressed or not. And working perfectly fine on Emulator and Samsung Focus. But when deploy to Nokia Lumia 800 and pressed "#" it wont resulted in Key.D2 and below code not working.
if (e.Key == System.Windows.Input.Key.D2)
{
myAutocompleteBox.Text = "#";
updateAutocompleteBox = true;
}
else if (e.Key == System.Windows.Input.Key.D3)
{
myAutocompleteBox.Text = "#";
updateAutocompleteBox = true;
}
else if (e.Key == System.Windows.Input.Key.Back)
{
if (myAutocompleteBox.Text != String.Empty && updateAutocompleteBox == true)
{
string autoCompleteText = myAutocompleteBox.Text;
myAutocompleteBox.Text = autoCompleteText.Substring(0, autoCompleteText.Length - 1);
}
}
Please guide me how can i capture "#" and "#" key pressed on my textbox. Thanks in Advance.
I think the value of D2 or D3 depends on the keyboard layout in use. In the EN-US Layout SHIFT+2 is # in DE-DE SHIFT+2 is doublequotes and D0 - D9 are variable based on the layout used. In your code you might have to take that into account when translating the key pressed to the String value.
Have a look at this.
It's got all the Key Enumeration for Windows Phone 7, had a look but couldn't spot # or #.
What value is being returned for e.Key?

How can I implement incremental (find-as-you-type) search on command line?

I'd like to write small scripts which feature incremental search (find-as-you-type) on the command line.
Use case: I have my mobile phone connected via USB, Using gammu --sendsms TEXT I can write text messages. I have the phonebook as CSV, and want to search-as-i-type on that.
What's the easiest/best way to do it? It might be in bash/zsh/Perl/Python or any other scripting language.
Edit:
Solution: Modifying Term::Complete did what I want. See below for the answer.
I get the impression GNU Readline supports this kind of thing. Though, I have not used it myself. Here is a C++ example of custom auto complete, which could easily be done in C too. There is also a Python API for readline.
This StackOverflow question gives examples in Python, one of which is ...
import readline
def completer(text, state):
options = [x in addrs where x.startswith(text)]
if state < options.length:
return options[state]
else
return None
readline.set_completer(completer)
this article on Bash autocompletion may help. This article also gives examples of programming bash's auto complete feature.
Following Aiden Bell's hint, I tried Readline in Perl.
Solution 1 using Term::Complete (also used by CPAN, I think):
use Term::Complete;
my $F;
open($F,"<","bin/phonebook.csv");
my #terms = <$F>; chomp(#terms);
close($F);
my $input;
while (!defined $input) {
$input = Complete("Enter a name or number: ",#terms);
my ($name,$number) = split(/\t/,$input);
print("Sending SMS to $name ($number).\n");
system("sudo gammu --sendsms TEXT $number");
}
Press \ to complete, press Ctrl-D to see all possibilities.
Solution 2: Ctrl-D is one keystroke to much, so using standard Term::Readline allows completion and the display off possible completions using only \.
use Term::ReadLine;
my $F;
open($F,"<","bin/phonebook.csv");
my #terms = <$F>; chomp(#terms);
close($F);
my $term = new Term::ReadLine;
$term->Attribs->{completion_function} = sub { return #terms; };
my $prompt = "Enter name or number >> ";
my $OUT = $term->OUT || \*STDOUT;
while ( defined (my $input = $term->readline($prompt)) ) {
my ($name,$number) = split(/\t/,$input);
print("Sending SMS to $name ($number).\n");
system("sudo gammu --sendsms TEXT $number");
}
This solution still needs a for completion.
Edit: Final Solution
Modifying Term::Complete (http://search.cpan.org/~jesse/perl-5.12.0/lib/Term/Complete.pm) does give me on the fly completion.
Source code: http://search.cpan.org/CPAN/authors/id/J/JE/JESSE/perl-5.12.0.tar.gz
Solution number 1 works with this modification. I will put the whole sample online somewhere else if this can be used by somebody
Modifications of Completion.pm (just reusing it's code for Control-D and \ for each character):
170c172,189
my $redo=0;
#match = grep(/^\Q$return/, #cmp_lst);
unless ($#match < 0) {
$l = length($test = shift(#match));
foreach $cmp (#match) {
until (substr($cmp, 0, $l) eq substr($test, 0, $l)) {
$l--;
}
}
print("\a");
print($test = substr($test, $r, $l - $r));
$redo = $l - $r == 0;
if ($redo) { print(join("\r\n", '', grep(/^\Q$return/, #cmp_lst)), "\r\n"); }
$r = length($return .= $test);
}
if ($redo) { redo LOOP; } else { last CASE; }