Is it possible to scan a barcode in multiple programs at the same time while using a Honeywell Xenon 1902 scanner to avo

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mailpcp
Posts: 1
Joined: 29 May 2017, 04:11

Is it possible to scan a barcode in multiple programs at the same time while using a Honeywell Xenon 1902 scanner to avo

29 May 2017, 04:20

Is it possible to scan a barcode in multiple programs at the same time while using a Honeywell Xenon 1902 scanner to avoid scanning the same barcode multiple times using AHK?
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Is it possible to scan a barcode in multiple programs at the same time while using a Honeywell Xenon 1902 scanner to

29 May 2017, 09:13

In all likelihood, no, as most scanners work by impersonating a keyboard, and you can only type into one application at a time - so this is a limitation of windows, not of the scanner.

What you COULD do, however, is teach AHK how to distinguish normal typing from a scan, and have it wait for the scan to finish in the first application, then switch to the second application and send the same key sequence.

This, however, is non-trivial - you would need to declare a hotkey for every single key that the scanner can send. (ie if the scanner can send a-z, 0-9 then you would need 36 hotkeys)
You would also need to set a "pre-amble" and "post-amble" on your barcode scanner, which is normally done by scanning in special barcodes from the manual.

You would need logic something like this:

1) Declare hotkey to pre-amble, post-amble and all normal characters the scanner can send. Make sure it is pass-through (~ prefix)
2) When the pre-amble key is detected, set a variable flag
3) In each of the character hotkeys, have it check the flag to see if it is set, and if so, store A_ThisHotkey in an array
4) When the post-amble char is detected, unset the flag and then switch to the other application and send the keys from the array
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Is it possible to scan a barcode in multiple programs at the same time while using a Honeywell Xenon 1902 scanner to

29 May 2017, 09:51

Here you go - here is some code which can duplicate a scan to multiple applications.

Configure the script with valid scan characters, your pre/post-amble keys and the ahk wintitle names of two or more applications.

The script is, by default, configured to use F11 for a pre-amble, F12 for a post-amble, and notepad and wordpad as the two "Scanner" apps. Valid chars are 1, 2, 3 and 4

So to test, open notepad and wordpad.

go into either app, hit F11 and then any combination of the 1,2,3 or 4 keys, then hit F12
It will tab to the other app, then type the sequence you just typed.

Code: Select all

#SingleInstance force
; User configuration

; Valid characters that the scanner can send
ValidChars := ["1", "2", "3", "4"]
; The scanner sends this before a scan
PreAmble := "F11"
; The scanner sends this at the end of a scan
PostAmble := "F12"
; These are the apps that you want the scan to be duplicated in
ScannerApps := ["ahk_exe notepad.exe", "ahk_exe wordpad.exe"]

; End of User configuration

; Internal vars
ScannedChars := []	; Holds a list of the scanned characters
ScanMode := 0		; Set to 1 while we are mid-scan
OriginalApp := 0	; The index of the app from ScannerApps that the scan happened in

; Bind the hotkeys for the ValidChars
Loop % ValidChars.length() {
	char := ValidChars[A_Index]
	fn := Func("ScannerCharHit").Bind(char)
	hotkey, % "~" char, % fn
}

; Bind the pre/post amble hotkeys
hotkey, % "~" PreAmble, ScanStart
hotkey, % "~" PostAmble, ScanStop

return

; Scanning Started
ScanStart:
	; Reset vars
	ScannedChars := []
	OriginalApp := 0
	; Work out which of the ScannerApps that we started in
	for i, app in ScannerApps {
		if (WinActive(app)){
			OriginalApp := i
			break
		}
	}
	; If it was a valid app, then enable ScanMode
	if (OriginalApp){
		ScanMode := 1
	}
	return

; Scanning finished
ScanStop:
	; Turn off ScanMode
	ScanMode := 0
	; Send the scanned keys to all the other apps...
	; Start off with the next one in the ScannerApps list
	i := OriginalApp + 1
	max := ScannerApps.length()
	; We will not need to do the app originally scanned in, so loop max-1 times
	Loop % max - 1 {
		; When we reach the end of the list, wrap back around to the start
		if (i > max)
			i := 1
		; Activate the app and wait a bit
		WinActivate, % ScannerApps[i]
		Sleep 100
		; Send the keys from ScannedChars
		for j, key in ScannedChars {
			Send % "{" key "}"
		}
		; Move on to the next item in the list
		i++
	}
	return

; A key from the ValidChars array was hit
ScannerCharHit(char){
	global ScannedChars, ScanMode
	
	; If we are in ScanMode...
	if (ScanMode){
		; ... Add it to the list of scanned characters
		ScannedChars.push(char)
	}
}
Elgin
Posts: 124
Joined: 30 Sep 2013, 09:19

Re: Is it possible to scan a barcode in multiple programs at the same time while using a Honeywell Xenon 1902 scanner to

29 May 2017, 12:03

I don't have one, but according to the scanner user manual:
https://www.manualslib.com/manual/12514 ... =39#manual
you can set it to work as a HID device.

If that's an option for your environment, you can use AHKHID to catch the scanner input specifically and do whatever you please with it.
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Is it possible to scan a barcode in multiple programs at the same time while using a Honeywell Xenon 1902 scanner to

29 May 2017, 13:00

Yes it's possible. I use it all the time. Just feed the output of the scan to an inputbox first and then use the variable in the programs you wish to use the barcode in.
rbabler
Posts: 4
Joined: 29 Mar 2021, 18:04

Re: Is it possible to scan a barcode in multiple programs at the same time while using a Honeywell Xenon 1902 scanner to

13 Apr 2021, 18:56

Just found this and need to ask a real basic question in the EvilC script looking at it and not knowing much about AHK in order to use it do you have to do this.
Hit F11 then scan Code then hit F12 to process rest of the script?????? Or is this programed into scanner?? I have one and it mentions the following "Set prefix & suffix" are these terms the same as what is mentioned in the script "Preamble & Postamble"
rbabler
Posts: 4
Joined: 29 Mar 2021, 18:04

Re: Is it possible to scan a barcode in multiple programs at the same time while using a Honeywell Xenon 1902 scanner to

21 Apr 2021, 10:54

WalkerOfTheDay wrote:
29 May 2017, 13:00
Yes it's possible. I use it all the time. Just feed the output of the scan to an inputbox first and then use the variable in the programs you wish to use the barcode in.
Wow how about a sample script for us that are not programmers to get us started!!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jdfnnl and 369 guests