magace 0 Posted October 16, 2012 (edited) 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! expandcollapse popupHotKeySet("{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 October 16, 2012 by magace Share this post Link to post Share on other sites
FireFox 260 Posted October 17, 2012 (edited) 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. expandcollapse popup#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 October 17, 2012 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_UDFMy Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme makerMy Examples : Capture tool | IP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewerMy 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