Jump to content
Sign in to follow this  
magace

How can I detect the "enter" sent from a bar code scanner

Recommended Posts

magace

So when my scanner scans something it automaticaly sends "enter" to submit the data. Im needing to detect when the enter is pressed so my script can hit tab twice then click a box simple enough. However its not detecting the enter from the scanner however when I manually hit enter everything works just fine. Here is my code!

HotKeySet("{END}", "Terminate")


#include <ImageSearch.au3>
#include <GDIPlus.au3>
#include <Misc.au3>


$fileD = @ScriptDir & "PGL.png"  ;PAGE LOADED
$fileE = @ScriptDir & "SUB3.png"  ;SUBMIT ITEM
Global $hDLL = DllOpen("user32.dll")


While 1
    Sleep(100)
    ToolTip("RUNNING",1074,2)
If _IsPressed("0D", $hDLL) Then
   ToolTip("ENTER WAS PRESSED ",1074,2)
   
   
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;

   
      
   $go = 1
 while $go = 1

_GDIPlus_Startup()
$hImageA =_GDIPlus_ImageLoadFromFile($fileD) ;this is the PAGE LOADED
$hBitmapA = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageA)
$x = 0
$y = 0
$result = _ImageSearch($hBitmapA, 1, $x, $y, 20, 0) ;Zero will search against your active screen
  If $result > 0 Then
  ToolTip("PAGE IS LOADED",0,0)
 $go = 0
 _GDIPlus_ImageDispose($hImageA)
_GDIPlus_Shutdown()
  Else
 ToolTip("WAITING FOR PAGE TO LOAD",0,0)
 SLEEP(1000)
 _GDIPlus_ImageDispose($hImageA)
_GDIPlus_Shutdown()
  EndIf
   WEnd
   
   
      
   Send("{TAB}")
   SLEEP(500)
   Send("{TAB}")
   SLEEP(500)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
$go1 = 1
 while $go1 = 1
_GDIPlus_Startup()
$hImageA =_GDIPlus_ImageLoadFromFile($fileE) ;this is the PART NUMBER BOX
$hBitmapA = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageA)
$x = 0
$y = 0
$result = _ImageSearch($hBitmapA, 1, $x, $y, 20, 0) ;Zero will search against your active screen
If $result > 0 Then
  ToolTip("WE FOUND PART NUMBER BOX",0,0)
  MouseMove($x, $y)
   $go1 = 0
_GDIPlus_ImageDispose($hImageA)
_GDIPlus_Shutdown()
Else
ToolTip("CANT FIND PART NUMBER BOX",0,0)
SLEEP(500)
_GDIPlus_ImageDispose($hImageA)
_GDIPlus_Shutdown()
EndIf
WEnd
   
   

DllClose($hDLL)

EndIf
WEnd




   
   
   
   
   
   
Func Terminate()
Exit 0 
EndFunc
Edited by magace

Share this post


Link to post
Share on other sites
FireFox

Hi,

The barcode scanner is like a keyboard, however you can detect it.

I don't remember right how it works, but as I see it sends 4 times the ALT code before sending text and ends with the UP code.

So in this example, It should focus the right edit control and retreive what is sent by the barcode scanner and then writting it in the console.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#include <WinAPI.au3>
#include <StructureConstants.au3>

Global $hHook, $hStub_KeyProc, $iALTDOWNCount = 0, $blCodeBarScannerWritting = False

$hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
$hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), _WinAPI_GetModuleHandle(0))

OnAutoItExitRegister("Cleanup")

Opt("GUIOnEventMode", 1)

$GUI = GUICreate("MyGUI", Default, Default)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$tbBarCodeScanner = GUICtrlCreateEdit("", 10, 300, Default, 40)

GUICtrlCreateEdit("", 10, 10, Default, 250)

GUISetState(@SW_SHOW, $GUI)

While 1
Sleep(10)
WEnd

Func _KeyProc($nCode, $wParam, $lParam)
If $nCode < 0 Then
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) ;Continue Processing
EndIf

If $wParam <> $WM_KEYDOWN Then
Local $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)

Switch DllStructGetData($tKEYHOOKS, "flags")
Case $LLKHF_ALTDOWN
If Not $blCodeBarScannerWritting Then
If $iALTDOWNCount = 4 Then
ConsoleWrite(GUICtrlRead($tbBarCodeScanner))
GUICtrlSetData($tbBarCodeScanner, "")

$iALTDOWNCount = 0
EndIf

$iALTDOWNCount += 1

If $iALTDOWNCount = 4 Then
$blCodeBarScannerWritting = True

ControlFocus($GUI, "", $tbBarCodeScanner)
EndIf
EndIf
Case $LLKHF_UP
If $blCodeBarScannerWritting Then
If DllStructGetData($tKEYHOOKS, "scanCode") = 28 Then
$blCodeBarScannerWritting = False
EndIf
EndIf
EndSwitch
EndIf

Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) ;Continue Processing
EndFunc ;==>_KeyProc

Func Cleanup()
_WinAPI_UnhookWindowsHookEx($hHook)
DllCallbackFree($hStub_KeyProc)
EndFunc ;==>Cleanup

Func _Exit()
Exit
EndFunc

Hope it works for you.

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×