Page 2 of 2

Re: NEW Barcode Input Capture (USB and RS232 compatible)

Posted: 15 Sep 2017, 04:32
by labrint
Unfortunately, this 2D barcode reader is from China and it did not come with a leaflet allowing me to add prefixes and suffixes. Is there a way to bind all characters using evilC's code? Its a pity to abandon his code since it works for numbers, does not skip characters, and distinguishes between keyboard and barcode. I have worked on the script using methods similar to yours jeeswg, because it looks very logical, but this method is the one we should follow, probably all that is needed is a couple of lines of code to bind all characters instead of just numbers. I simply do not understand what is going on in evilC's code enough to fix it.

Re: NEW Barcode Input Capture (USB and RS232 compatible)

Posted: 15 Sep 2017, 07:28
by jeeswg
I've taken a look a AHKHID for the first time, it was reasonably easy to get going, thanks to this example script:
AHK keyboard hook + AHKHID causing buggy behavior - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 925#p87925

This is able to distinguish between my 2 keyboards, and it can handle whether shift is pressed or not. So this may be a good basis from which to proceed.

Code: Select all

;[AHKHID functions]
;GitHub - jleb/AHKHID: An AHK implementation of the HID functions
;https://github.com/jleb/AHKHID

#Include AHKHID.ahk
AHKHID_UseConstants()
AHKHID_Register(1, 6, A_ScriptHwnd, RIDEV_INPUTSINK)
OnMessage(0xFF, "InputMsg")
vList = ;continuation section
(` %
#',-./0123456789;=[\]`abcdefghijklmnopqrstuvwxyz
)
vListS = ;continuation section
(` %
~@<_>?)!"£$%^&*(:+{|}¬ABCDEFGHIJKLMNOPQRSTUVWXYZ
)
global oArray := {}
Loop, Parse, vList
	oArray["" A_LoopField] := "" SubStr(vListS, A_Index, 1)
return

;==================================================

InputMsg(wParam, lParam)
{
	local r, h
	Critical
	r := AHKHID_GetInputInfo(lParam, II_DEVTYPE)
	if (r = RIM_TYPEKEYBOARD)
	{
		h := AHKHID_GetInputInfo(lParam, II_DEVHANDLE)
		vOutput := ""
		. "MakeCode: " (vSC := AHKHID_GetInputInfo(lParam, II_KBD_MAKECODE))
		. "`r`n Flags: " AHKHID_GetInputInfo(lParam, II_KBD_FLAGS)
		. "`r`n VKey: " (vVK := AHKHID_GetInputInfo(lParam, II_KBD_VKEY))
		. "`r`n Message: " AHKHID_GetInputInfo(lParam, II_KBD_MSG)
		. "`r`n ExtraInfo: " AHKHID_GetInputInfo(lParam, II_KBD_EXTRAINFO)
		. "`r`n Name: " AHKHID_GetDevName(H, True)
		vListMod := ""
		GetKeyState("Shift", "P") ?? vListMod .= "S"
		GetKeyState("Ctrl", "P") ?? vListMod .= "C"
		(GetKeyState("LWin", "P") || GetKeyState("RWin", "P")) ?? vListMod .= "W"
		GetKeyState("Alt", "P") ?? vListMod .= "A"
		vKeyName1 := GetKeyName(Format("vk{:x}", vVK))
		vKeyName2 := GetKeyName(Format("sc{:x}", vSC))
		if GetKeyState("Shift", "P")
			vKeyName := oArray["" vKeyName1]
		else
			vKeyName := vKeyName1
		ToolTip, % vKeyName "`r`n" vListMod " " vKeyName1 " " vKeyName2 "`r`n" vOutput
		return 0
	}
}

;==================================================

Re: NEW Barcode Input Capture (USB and RS232 compatible)

Posted: 07 Oct 2017, 09:06
by jeeswg
I've written a script that tries to combine my approach with that of evilC:

Code: Select all

#NoEnv
#SingleInstance force

;==============================
vList = ;continuation section
(` %
#',-./0123456789;=[\]`abcdefghijklmnopqrstuvwxyz
)
vListS = ;continuation section
(` %
~@<_>?)!"£$%^&*(:+{|}¬ABCDEFGHIJKLMNOPQRSTUVWXYZ
)
global oArray := {}
Loop, Parse, vList
	oArray["" A_LoopField] := "" SubStr(vListS, A_Index, 1)
;==============================

Loop, Parse, vList
{
	vChar := A_LoopField
	fn := Func("BarCodeHandler").Bind(vChar)
	Hotkey, % "*$~" vChar, % fn, On
}
return

BarCodeHandler(vKey)
{
	global vLog
	if GetKeyState("Shift", "P")
		vKey := oArray["" vKey]

	vLog .= vKey
	if (StrLen(vLog) > 4 && A_TimeSincePriorHotkey < 6000)
	{
		SetTimer, TheBigShebang, -60
	}
	else if (A_TimeSincePriorHotkey >= 6000)
	{
		vLog := vKey
	}
}

TheBigShebang:
if !(vLog = "")
	MsgBox, % "You scanned barcode: " vLog
return

Re: NEW Barcode Input Capture (USB and RS232 compatible)

Posted: 07 Jan 2019, 06:03
by labrint
Problems;

Captures keyboard aswell.
Doesn't start new capture with every barcode scan. It sometimes concatenates with previous captures.
It does not always capture all the text. It misses out on some characters.

Jeeswg, I have modified Joedf's script. It captures uppercase text and lowercase, it captures numbers and other characters. Now I need it to capture whitespace (A_Space, space) perhaps tabs. Also I have an issue that it requires a number in the barcode to capture something. If text is alone, it does not capture.

https://www.autohotkey.com/boards/viewt ... 76&t=60613