AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Hotkey with regex

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Stom2008
Guest





PostPosted: Thu Aug 21, 2008 8:53 am    Post subject: Hotkey with regex Reply with quote

Hello AHK Forum,

I like to know if it is possible to use a kind of regex together with hotkeys
I like to do the following.

I will type:
0001-123456789 and ahk should convert it to 000112345679
0001-987654321 -> 0001987654321
0102-121212121 -> 0102121212121

for all possible numbers I like to replace the - after the number is typed.

I think the regex should be:
([0-9]{4,})-([0-9]{9,})

But I did not know if I can do it in ahk and how?

Best Regards,
Marcus
Back to top
Hasso



Joined: 23 Mar 2005
Posts: 158
Location: Germany

PostPosted: Thu Aug 21, 2008 9:52 am    Post subject: Re: Hotkey with regex Reply with quote

Stom2008 wrote:

0001-123456789 and ahk should convert it to 000112345679

I think there is a typo as the "8" has disappeared in the converted number?
Your problem seems rather strange to me - why don't you simply type the number without the "-"???
_________________
Hasso

Programmers don't die, they GOSUB without RETURN
Back to top
View user's profile Send private message
Guest






PostPosted: Thu Aug 21, 2008 9:56 am    Post subject: Reply with quote

...

Yes, this is a typo.
0001-123456789 and ahk should convert it to 0001123456789

I do not really type the number. The nuber is "typed" by barcode scanning.
And the scan returns the number with the "-"
In the system I need the number without the "-"

Best Regards,
Marcus
Back to top
[VxE]



Joined: 07 Oct 2006
Posts: 1496

PostPosted: Thu Aug 21, 2008 12:30 pm    Post subject: Reply with quote

You can write a script that catches scanner-speed input and disables the [-] key for a split second after four numbers have been 'typed' really quickly.
Code:
Loop % troll := 10
   Hotkey, % "~" SubStr(A_Index, 0), scan_handler, on
scan_handler:
troll := troll * ( A_TimeSincePriorHotkey < 20 ) + 1
Hotkey, -, scan_handler, % (troll > 2) ? "on" : "off"
return
untested
_________________
My Home Thread
More Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Back to top
View user's profile Send private message
Razlin



Joined: 05 Nov 2007
Posts: 434
Location: canada

PostPosted: Thu Aug 21, 2008 12:36 pm    Post subject: Reply with quote

ummm why dont you just

Code:

mystring = "0000-123456789"

StringReplace, MyString, MyString, -, ,


replace the - with nothing.

no regex required.
_________________
-=Raz=-
Back to top
View user's profile Send private message
stom2008
Guest





PostPosted: Thu Aug 21, 2008 12:59 pm    Post subject: Reply with quote

Thanks for your answers

@[VxE]
I tried the script but nothing happens if the number is typed

@Razlin
That was my first idea. But I have no idea how to become the "scanner-type-input" into a variable to replace the "-"

Best Regards,
Marcus
Back to top
Razlin



Joined: 05 Nov 2007
Posts: 434
Location: canada

PostPosted: Thu Aug 21, 2008 2:29 pm    Post subject: Reply with quote

how about a hotsting.

Code:

:*?:-::
return



Replace - with nothing.


Smile
_________________
-=Raz=-
Back to top
View user's profile Send private message
Razlin



Joined: 05 Nov 2007
Posts: 434
Location: canada

PostPosted: Thu Aug 21, 2008 2:55 pm    Post subject: Reply with quote

hotstring may work but I'm not sure.. but for your other question. you can receive input with

Code:
Input, Variable_name_here, L10


Variable_name_here will contain 10 chars

Change L10 to what ever limit you want,
you can then use

stringreplace on Variable_name_here

anyhow.. hope one of these 2 work for you.
_________________
-=Raz=-
Back to top
View user's profile Send private message
[VxE]



Joined: 07 Oct 2006
Posts: 1496

PostPosted: Thu Aug 21, 2008 9:06 pm    Post subject: Reply with quote

stom2008 wrote:
@[VxE]
I tried the script but nothing happens if the number is typed

Of course, nothing is supposed to happen when a human 'types' numbers. That example script is only supposed to show how AHK might watch numeric input and, if it is too fast, deactivate the [-] key.

btw: you never mentioned whether your scanner's input simulates the numpad keys or the regular number keys... could be important.

This example tries to detect speed-input and then selects the input, cuts it, replaces [-], and pastes result.
Code:
#UseHook
Loop 10 ; turn the number keys into hotkeys
   Hotkey, % "~" SubStr(A_Index, 0), ~-, on
~-:: ; the minus key is a hotkey too
troll++, troll *= A_TimeSincePriorHotkey < 21
If (Troll > 12) ; if 14 or more numbers or minus
{ ; signs have been entered with a delay under 21ms
   clip := clipboardall ; save clipboard
   clipboard := "" ; clear clipboard
   SendInput +{left 14}^x ; cut previous 14 chars
   clipwait, 1 ; wait for number to sow up
   Stringreplace, clipboard, clipboard, -
   SendInput ^v ; paste number without minus
   clipboard := clip ; restore clipboard
   clip := ""
}
return

_________________
My Home Thread
More Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group