I am scanning 4 barcodes that sends as N123P123Q12V123456 with different length on the numbers. When I scan it splits the string correct at the characters, and outputs it with the enter as it should. But I can't press any key after the scan, let's say that I want to write something manually - it does not work with this code.
I would also like to add F1, delay, F4 at the end of the string (after V-string). Is it just Send {F1} ?
Loop
{
Input, OutputVar, L26 M
if (RegExMatch(OutputVar, "iO)([A-Z]\d+)([A-Z]\d+)([A-Z]\d+)([A-Z]\d+)", Output))
for k,v in % StrSplit(RegExReplace(OutputVar,"(?<=\d)[A-Z]\d+","|$0"),"|") {
send, % v "{Enter}"
Sleep, 500
}
}
Related
coloured_text:
send {^}%rand%
return
~t::
Random, rand, 1, 3
SetTimer, coloured_text, 500
return
~esc::
~enter::
SetTimer, coloured_text, Off
return
Code: When "t" is pressed the variable RAND gains a random number from 1-3. A label is then called 0.5 seconds later. This label sends the text "^%RAND%" i.e. ^1. The Label repeats every .5 seconds until enter/esc is hit. While all of this is happening though, as soon as I press "t", I am also manually typing sentences out i.e. "Big red dog".
So a good output might looks like: *"Bi^1g red ^3dog".
But sometimes I get somethin like: *"Bi^g1 red ^do3g".
In other words I need the label to send the two characters of "{^}%rand%" i.e. "^1" without breaks/gaps. And I need this to be done without interfering with my normal typing, whatever I may be typing. And I can't use any of the other sends (sendinput sendplay sendevent), just normal send.
That looks like color control codes of IRC, you can use something like this either via hotkey or hotstring.
It creates a small Gui with just an Edit so you can input the text you want colorized and when you press enter every 3 characters (configurable) get a random color.
If you still like your approach, you can take a look into BlockInput docs and wrap Send % "{^}" rand between them. Is reliable as long as you run the script with UI Access
F1::Colorize()
:*X:/color::Colorize()
Colorize()
{
Gui C:New, +LastFound -SysMenu
Gui Add, Edit, -WantReturn r5 w200
Gui Add, Button, Default Hidden x0 y0, OK
Gui Show,, Colored Text
}
CButtonOK()
{
GuiControlGet Line,, Edit1
Gui Destroy
Out := "", i := 0
loop parse, Line
{
if (A_LoopField = " ")
{
Out .= " "
continue
}
/* Every 3 characters
*/
if !Mod(i++, 3)
{
Random r, 1, 3
Out .= "{^}" r
}
Out .= A_LoopField
}
Send % Out
}
CGuiEscape()
{
Gui Destroy
ExitApp
}
When I type, I want my script to replace:
"ab" to "x"
"ac" to "y"
"a[more than 300ms]b" - don't replace, just leave "ab"
So, it should replace only if time between "a" and "b"/"c" is less than 300ms
tried doing this:
a & b :: Send x
a & c :: Send y
But it obviously doesn't 'forgive' me any delay
Would be great to get any hints, thanks!
A hotstring is usually good for replacements. To add that delay, here's a simple thing I could come up with:
~*a::APressTime := A_TickCount
:*B0:ab::
if(A_TickCount - APressTime <= 300)
SendInput, % "{BS 2}x"
return
First a simple hotkey for A that just saves the current system time with A_TickCount.
Then a hotstring to which I set some options you're likely going to want to use:
* so you don't need to type an ending character.
B0 so it doesn't backspace the letters ab automatically.
You might also want to use the ? option so the hotstring also works while "inside of a word". Add it in if you want.
Then we compare the current system time to the time when a was last pressed. If it's 300ms or less, send backspace twice followed up by x.
({BS 2} is same as {Backspace 2} or {Backspace}{Backspace})
To do the same with ac, just copy paste the hotstring again and switch b with c, and x with y.
Alternatively, here's something a bit more fancy to put them in the same hotstring label with a ternary:
:*B0:ab::
:*B0:ac::
if(A_TickCount - APressTime <= 300)
SendInput, % "{BS 2}" (SubStr(A_ThisHotkey, 0) = "b" ? "x" : "y")
return
I want a hotkey or hotstring (whatever is easier), so I can easily convert e.g.
1:5 into [1,2,3,4,5] or
3:7 into [3,4,5,6,7] etc..
I want this to work for all integers...
So I want "multiple variants of the same hotstring" (or, if easier: a hotkey that works somewhat similar: e.g. pressing strg + h and typing 1:3 should produces [1,2,3] )
It should recognize that I typed a number followed by colon followed by another number, and then expand correspondingly..
I looked into the Input function, but it does not seem to be exactly what I want..
I don't need a working solution. Hints & links or keywords for further googling are already helpful..
After typing +h or pressing strg+h, type two numbers to produce the desired outcome:
:*:+h::
^h::
nr := "" ; empty variable's content
end_nr := ""
Input, var, L2 ; Length limit=2
; Input, var, L2 V ; V: Visible
If var is not integer
{
MsgBox, "%var%" is not integer
return
}
first_nr := SubStr(var, 1, 1)
second_nr := SubStr(var, 0)
if (first_nr >= second_nr)
{
MsgBox, "%first_nr%" is greater or equal "%second_nr%"
return
}
Loop
{
nr++ ; increase the number in the variable "nr" by 1 in each iteration
if (nr < first_nr)
continue
If (nr = second_nr)
break
end_nr .= nr . "," ; concatenate the outputs by adding a comma to each one
}
If (first_nr = 0)
MsgBox, "0,%end_nr%%second_nr%"
else
MsgBox, "%end_nr%%second_nr%"
return
Similar to what this question covers, I'm trying to bind two sequences of keys.
Ideally I'd like to bind Alt DOWN,-,-,-,Alt UP to an em-dash (—) and Alt DOWN,-,-,Alt UP to an en-dash (–).
What I have almost works for em-dashes but not quite:
; Em-dash
!-::
Input Key, L1
if Key=-
Input Key, L1
if Key=-
Send {ASC 0151}
return
; En-dash
;!-::
;Input Key, L1
;if Key=-
;Send {ASC 0150}
;return
The em-dash sequence works like Alt+-,-,-, instead of what I'm trying to match. I'm not sure how to only test for Alt DOWN and Alt UP. The en-dash sequence fails altogether to bind because !- has already been bound.
Have a look at this one:
dashCount := 0
!-::
dashCount++
if(dashCount = 1) {
SetTimer, WaitForAlt, -1
}
return
WaitForAlt:
KeyWait, Alt
if(dashCount = 2) {
Send {ASC 0150}
} else if(dashCount = 3) {
Send {ASC 0151}
}
dashCount := 0
return
It seems to do the job well. The code works by counting each time Alt + - gets pressed. Concurrently, a pseudo-thread is spawned that waits for Alt to be released and then sends the appropriate dash, depending on the counter.
I'm using AutoHotKey and I want to achieve something particular.
I have an hotkey that should perform a certain action, inside this hotkey, I would like to code something to detect if I only press the "C" key, or if I press "C" then "L" keys.
If there is only the "C" key pressed, then it should perform an action, otherwise , if "C" then "L" keys are pressed it should do another action.
But I can't do this as I don't really understand KeyWait, I mean how can I do something like that :
if(KeyWait, C){
firstAction
else {
if(KeyWait, C){
if(KeyWait, L){
anotherAction
}
}
Solved using the input function.
; Get one character and store it in the Character variable
Input, Character, L1
If Character = C
{
; Give up to half of one second to type L
Input, Character, L1 T0.5
If Character = L
MsgBox % "We have C and L"
else
MsgBox % "Just C here, give an L next time"
}