Crazy Idea: erase typing Topic is solved
Crazy Idea: erase typing
Hi all,
I'm grappling with a situation where I have an application that I don't want people to type into a certain field.
I need them to use a barcode scanner (to enforce accuracy).
One thing I could do, which sounds a little nuts... is to watch the timing of the keystrokes, and if at any time the spacing between keystrokes is greater than 50ms, say, that AHK does a ctrl-a delete (select all, then delete)... continually erasing anything that is typed.
Note: I only want this code to be operating when a particular field has focus.
The barcode scanner will type much faster... thus all characters would be allowed (including the Carriage Return that would cause the field to lose focus, thus stopping the routine).
Basically, I'm in over my head on all of this... so what does this code look like?
Sorry to ask for such extreme hand holding.
R
I'm grappling with a situation where I have an application that I don't want people to type into a certain field.
I need them to use a barcode scanner (to enforce accuracy).
One thing I could do, which sounds a little nuts... is to watch the timing of the keystrokes, and if at any time the spacing between keystrokes is greater than 50ms, say, that AHK does a ctrl-a delete (select all, then delete)... continually erasing anything that is typed.
Note: I only want this code to be operating when a particular field has focus.
The barcode scanner will type much faster... thus all characters would be allowed (including the Carriage Return that would cause the field to lose focus, thus stopping the routine).
Basically, I'm in over my head on all of this... so what does this code look like?
Sorry to ask for such extreme hand holding.
R
Re: Crazy Idea: erase typing
Why not simply https://www.autohotkey.com/docs/commands/BlockInput.htm until the bar code scanner has done its job
Alternatively, have a look at example #2 https://www.autohotkey.com/docs/commands/_If.htm#ExWordDelete (#If ActiveControlIsOfClass("Edit")) and use that to block input for a-z 0-9 hotkeys and "block" input for the bar code scanner field
Alternatively, have a look at example #2 https://www.autohotkey.com/docs/commands/_If.htm#ExWordDelete (#If ActiveControlIsOfClass("Edit")) and use that to block input for a-z 0-9 hotkeys and "block" input for the bar code scanner field
Re: Crazy Idea: erase typing
I don't think that would work because, as I understand it, the mouse is also blocked... which means the user couldn't click away from the field... next, the barcode scanner is interpreted as a keyboard, so it would also be blocked.ahk7 wrote: ↑04 Oct 2022, 12:26Why not simply https://www.autohotkey.com/docs/commands/BlockInput.htm until the bar code scanner has done its job
Alternatively, have a look at example #2 https://www.autohotkey.com/docs/commands/_If.htm#ExWordDelete (#If ActiveControlIsOfClass("Edit")) and use that to block input for a-z 0-9 hotkeys and "block" input for the bar code scanner field
R
Re: Crazy Idea: erase typing
@ahk7, a typical scanner is just another HID device and to Windows, appears as another keyboard. You can attach multiple keyboards to a PC and Windows will accept input from all of them identically. AHK can not differentiate which keyboard (or HID) that input is coming from. From the BlockInput documentation:
I've been thinking about a solution, but so far no joy.
Russ
The BlockInput command will block the scanner as well as the keyboard because it can't tell the difference.This mode blocks all user inputs unconditionally. Specify one of the following words:
On: The user is prevented from interacting with the computer (mouse and keyboard input has no effect).
I've been thinking about a solution, but so far no joy.
Russ
Re: Crazy Idea: erase typing
In that case: perhaps https://github.com/evilC/AutoHotInterception
(never used it myself)
Forum viewtopic.php?f=6&t=45307AutoHotInterception (AHI) allows you to execute AutoHotkey code in response to events from a specific keyboard or mouse...
(never used it myself)
Re: Crazy Idea: erase typing
Solved in essentially the exact way I described:
I reset the Global variable OldTime whenever the field is activated... the rest is self explanatory.
Setting the CheckNum boolean tells the function if it's supposed to be working or not.
I also need to add the numpad keys... but this does the trick.
I reset the Global variable OldTime whenever the field is activated... the rest is self explanatory.
Setting the CheckNum boolean tells the function if it's supposed to be working or not.
I also need to add the numpad keys... but this does the trick.
Code: Select all
~1:: NumKeyPress()
~2:: NumKeyPress()
~3:: NumKeyPress()
~4:: NumKeyPress()
~5:: NumKeyPress()
~6:: NumKeyPress()
~7:: NumKeyPress()
~8:: NumKeyPress()
~9:: NumKeyPress()
~0:: NumKeyPress()
NumKeyPress(){
Global OldTime ;so the function knows to use the global variable
Global CheckNum ;""
If CheckNum{
DeltaTime = 0
If (OldTime = 0){ ;for first character, just grab a tick
OldTime := A_TickCount ;only good for systems on for < 49.7 days!!!??
}
Else{ ;If this isn't the first press
NowTime := A_TickCount ;Get now
DeltaTime := NowTime - OldTime ;compare to previous press
OldTime := NowTime ;Remember the now time as the old
If (DeltaTime > 100) { ;make sure it's less than .12 seconds
Send ^a ;if not... select all
Send {del} ;and delete it..
OldTime := 0 ;then reset the process
}
}
}
Re: Crazy Idea: erase typing
Now that the problem is solved I would like to add something: "Do a program fool safe and no one will be so fool to use your program". It is a non-written programming rule.
When you introduce a new technology (bar scanner) you need to provide a secondary solution: barcode scanneer don't recognize a bar code, dirty on barcode paper, reflections on the plastic makes barcode scanner fail, etc. How will handle this situation your people? Easy: stop the line, ask for another product that has a cleaner barcode and start again. So, you must provide a way to type a barcode by hand, bottom line.
Since you want everybody uses the barcode scanner, place a button that makes posible to introduce by hand but disable it when he press Enter or barcode has been recognized, and makes default option to be scanned.
In my honest opinion, supervisor is the one to encourage people to use barcode scanner, not a programmer.
When you introduce a new technology (bar scanner) you need to provide a secondary solution: barcode scanneer don't recognize a bar code, dirty on barcode paper, reflections on the plastic makes barcode scanner fail, etc. How will handle this situation your people? Easy: stop the line, ask for another product that has a cleaner barcode and start again. So, you must provide a way to type a barcode by hand, bottom line.
Since you want everybody uses the barcode scanner, place a button that makes posible to introduce by hand but disable it when he press Enter or barcode has been recognized, and makes default option to be scanned.
In my honest opinion, supervisor is the one to encourage people to use barcode scanner, not a programmer.
Re: Crazy Idea: erase typing
Thank you for your comments.Lepes wrote: ↑05 Oct 2022, 06:04Now that the problem is solved I would like to add something: "Do a program fool safe and no one will be so fool to use your program". It is a non-written programming rule.
When you introduce a new technology (bar scanner) you need to provide a secondary solution: barcode scanneer don't recognize a bar code, dirty on barcode paper, reflections on the plastic makes barcode scanner fail, etc. How will handle this situation your people? Easy: stop the line, ask for another product that has a cleaner barcode and start again. So, you must provide a way to type a barcode by hand, bottom line.
Since you want everybody uses the barcode scanner, place a button that makes posible to introduce by hand but disable it when he press Enter or barcode has been recognized, and makes default option to be scanned.
In my honest opinion, supervisor is the one to encourage people to use barcode scanner, not a programmer.
What do you do when there is no supervisor? What do you do when the operators do not speak or read the language of the organization? And finally, what do you do when the need is much stronger than "encourage", but is in fact "absolute requirement"?
But to your point, the code includes a "secret" key press combination that disables the system if needed.
Re: Crazy Idea: erase typing Topic is solved
Here is an updated/better solution:
This requires that every numeric keystroke must occur within 50ms of the previous, or a timer will destroy the contents of the field. This is a far more aggressive approach which removes doing maths or the use of the tick counter.
Code: Select all
~1:: NumKeyPress()
~2:: NumKeyPress()
~3:: NumKeyPress()
~4:: NumKeyPress()
~5:: NumKeyPress()
~6:: NumKeyPress()
~7:: NumKeyPress()
~8:: NumKeyPress()
~9:: NumKeyPress()
~0:: NumKeyPress()
~Numpad1:: NumKeyPress()
~Numpad2:: NumKeyPress()
~Numpad3:: NumKeyPress()
~Numpad4:: NumKeyPress()
~Numpad5:: NumKeyPress()
~Numpad6:: NumKeyPress()
~Numpad7:: NumKeyPress()
~Numpad8:: NumKeyPress()
~Numpad9:: NumKeyPress()
~Numpad0:: NumKeyPress()
CheckNum := True
NumKeyPress(){
Global CheckNum ;Use the Global boolean flag
If CheckNum{ ;Only perform the check if the flag is set True
SetTimer, KillContents, 50 ;Kill the contents in 50ms
}
Return
KillContents:
Send ^a ;if the timer expires select all
Send {del} ;and delete it..
SetTimer, KillContents, off ;Kill the timer
Return
}
Re: Crazy Idea: erase typing
Ok, I understand. You kept in mind everything. I would suggest another Shorcut to disable once the barcode scanner. If someone catch the global one, you are in the same position.Ryder wrote: ↑05 Oct 2022, 10:22Thank you for your comments.
What do you do when there is no supervisor? What do you do when the operators do not speak or read the language of the organization? And finally, what do you do when the need is much stronger than "encourage", but is in fact "absolute requirement"?
But to your point, the code includes a "secret" key press combination that disables the system if needed.
The solution is to "touch their pocket": people that not use bar code scanner will be economically punished. There isn't mind weather it is true or not, the important thing is they believe its true