NEW Barcode Input Capture (USB and RS232 compatible)

Get help with using AutoHotkey and its commands and hotkeys
labrint
Posts: 49
Joined: 14 Jun 2017, 05:06

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

15 Sep 2017, 04:32

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.
User avatar
jeeswg
Posts: 5288
Joined: 19 Dec 2016, 01:58
Location: UK

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

15 Sep 2017, 07:28

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
	}
}

;==================================================
User avatar
jeeswg
Posts: 5288
Joined: 19 Dec 2016, 01:58
Location: UK

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

07 Oct 2017, 09:06

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

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], WeThotUWasAToad and 133 guests