Jump to content

Trigger Macro with Barcode


Recommended Posts

This is my first post. I've been using AutoIt for about a year. I am not the greatest but not useless either. I did search for my question before posting.

 

Can someone PLEASE help me write a script that detects a string of characters when scanned (I don't really care what they are so long as I can put it into a barcode) then simply emulates the an up arrow press.

My symbol scanner is configured to insert a carriage return after the scan, so that ASCII code may be need incorporated at the end of the string.

 

Why I want this? I'm at work scanning equipment into an excel list and oops! I hit the wrong barcode. Currently I have to walk into the next room over to the computer to simply press the up key on the keyboard. Then I have to return to the equipment and figure out where I left off.     It would be so much easier to just scan a nearby barcode and proceed with the equipment scanning.    ...I 99% sure that this is not possible to achieve this with just a normal barcode.

 

Any help would be appreciated.

 

Link to comment
Share on other sites

After thinking about this for a few minutes I realized the macro would probably need to be more than just "press up".

I think it will need to "press up" "delete whatever our barcode typed" then another "press up"

The second delete would be unnecessary as the "oops" scan would be overwritten with the new scan due to the nature of excel.

Link to comment
Share on other sites

Test this script what you get from your barcodescanner:

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

Example()

Func Example()
    GUICreate(" My GUI input accept Barcode", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45)
    Local $idScan = GUICtrlCreateInput("", 10, 5, 300, 20)

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idScan
                MsgBox($MB_SYSTEMMODAL, "scanned", GUICtrlRead($idScan))
                ;your actions here
                GUICtrlSetData($idScan,''); clear input for next scan
        EndSwitch
    WEnd

EndFunc   ;==>Example

 

Link to comment
Share on other sites

This is what you want

and a simplistic example

#include <HotString.au3>

HotStringSet("Specified Barcode{enter}", MyFunc)

While 1
    Sleep(10)
WEnd

Func MyFunc()
    Send("{Up}")
    Send("^{a}")
    Send("{Delete}")
EndFunc

(A more reliable option would probably be to use an _Excel_* function but I've never used the Excel UDF)

Link to comment
Share on other sites

You don´t need AutoIt for your task!

In Excel, create an input-control, in which you scan your barcodes. Scanning directly into a sheet leads to your problems...

With some lines of VBA, you can write those barcodes into the cells you want. If you detect an error during scanning, you can scan a "JumpUpOneLine"-Barcode, or other previously created barcodes to control your application.

Link to comment
Share on other sites

On 8/26/2016 at 5:36 PM, AutoBert said:

Test this script what you get from your barcodescanner:

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

Example()

Func Example()
    GUICreate(" My GUI input accept Barcode", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45)
    Local $idScan = GUICtrlCreateInput("", 10, 5, 300, 20)

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idScan
                MsgBox($MB_SYSTEMMODAL, "scanned", GUICtrlRead($idScan))
                ;your actions here
                GUICtrlSetData($idScan,''); clear input for next scan
        EndSwitch
    WEnd

EndFunc   ;==>Example

 

This one opens a control to scan into, then repeats what I scanned. I guess it could be coded to watch for the "special" barcode to send the needed commands or default to pasting the input into the desired spread sheet. Problem is, I would have to make a macro for every sheet, or make a dropdown to choose the sheet and add to it every time there is a new sheet. This one requires a lot of maintenance.

Link to comment
Share on other sites

On 8/26/2016 at 5:43 PM, InunoTaishou said:

This is what you want

and a simplistic example

#include <HotString.au3>

HotStringSet("Specified Barcode{enter}", MyFunc)

While 1
    Sleep(10)
WEnd

Func MyFunc()
    Send("{Up}")
    Send("^{a}")
    Send("{Delete}")
EndFunc

(A more reliable option would probably be to use an _Excel_* function but I've never used the Excel UDF)

This feels like exactly what I am looking for. However, I can't seem to get it to work.

I've tried: 

HotStringSet("UPARROW{enter}", MyFunc)

HotStringSet("UPARROW", MyFunc)

HotStringSet("*UPARROW*{enter}", MyFunc)

HotStringSet("*UPARROW*", MyFunc)

 

My barcode reads: UPARROW followed by a carriage return (enter) when scanned.

I have not yet read any documentation yet on "HotString.au3" which I have copied into the "include" folder.

Link to comment
Share on other sites

On 8/27/2016 at 4:12 AM, AndyG said:

You don´t need AutoIt for your task!

In Excel, create an input-control, in which you scan your barcodes. Scanning directly into a sheet leads to your problems...

With some lines of VBA, you can write those barcodes into the cells you want. If you detect an error during scanning, you can scan a "JumpUpOneLine"-Barcode, or other previously created barcodes to control your application.

I feel this would play out very similar to AUTOBERT's solution. Except there would be less maintenance if I were to include it into the personal.xlsb macros.

...What leads to my problems are the barcodes being printed too close together and scanning the wrong one, not scanning directly into the sheet.

I'll look into this solution if the AutoIt route fails. I think the AutoIt solution would be useful to all those people searching for an "up arrow" barcode.

Link to comment
Share on other sites

  • 1 month later...

I found a solution.

1st id like to say LifeHacker's "Texter" would have been great but it gave inconsistent results.

"text-expander" works great for this need. I can specify different instructions for different applications. (In notepad I need to select the entire line before deleting it whereas, excel I do not because I'm deleting the contents of a cell)

Link to comment
Share on other sites

I had a problem similar to this before, and this is how I handled this

First I set a hotkey

HotKeySet("{F9}", "BarcodeScannerInput")

Then I configured the barcode scanner to TYPE OUT (like a keyboard) F9, a 20ms pause, the scanned code, and then ENTER. I captured the code like this:

Func BarcodeScannerInput()
    ; Only accept input if my program is active. This is optional
    if WinGetHandle("[active]") = $GUI Then
        ConsoleWrite("Scanner triggered"&@CRLF)
        ; Create an inputbox that will dissappear after 1 second. the scanner types much faster than that so it was reliable
        $temp = InputBox("","Barcode input now!",default, default, default, default, -0, -0, 1)
        If $temp <> "" Then
            ; DO STUFF HERE! $temp is the code
            consolewrite("Scanned code: "&$temp&@CRLF)
        EndIf
        
    ; Other half of "Only if my program is active" bit. Disable hotkey, send key, re-enable hotkey
    Else
        HotKeySet("{F9}")
        Send("{F9}")
        HotKeySet("{F9}", "BarcodeScannerInput")
    EndIf
EndFunc

It was a very duct-tape approach to be sure, but every computer supports HID and it was reliable enough. The software I used this in has been in use for two years with no complaints.

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

21 hours ago, corgano said:

I had a problem similar to this before, and this is how I handled this

First I set a hotkey

HotKeySet("{F9}", "BarcodeScannerInput")

Then I configured the barcode scanner to TYPE OUT (like a keyboard) F9, a 20ms pause, the scanned code, and then ENTER. I captured the code like this:

Func BarcodeScannerInput()
    ; Only accept input if my program is active. This is optional
    if WinGetHandle("[active]") = $GUI Then
        ConsoleWrite("Scanner triggered"&@CRLF)
        ; Create an inputbox that will dissappear after 1 second. the scanner types much faster than that so it was reliable
        $temp = InputBox("","Barcode input now!",default, default, default, default, -0, -0, 1)
        If $temp <> "" Then
            ; DO STUFF HERE! $temp is the code
            consolewrite("Scanned code: "&$temp&@CRLF)
        EndIf
        
    ; Other half of "Only if my program is active" bit. Disable hotkey, send key, re-enable hotkey
    Else
        HotKeySet("{F9}")
        Send("{F9}")
        HotKeySet("{F9}", "BarcodeScannerInput")
    EndIf
EndFunc

It was a very duct-tape approach to be sure, but every computer supports HID and it was reliable enough. The software I used this in has been in use for two years with no complaints.

I looks like your code watches for the "{F9}" Key, and not the text "F9". 

It also looks like you scanning an F9 barcode, then, at least 20ms later, scanning something else for this code to work with. is that right?

I will only need to trigger code with the first scan.

I'm going to give this a try after my warehouse is finished preparing for an inventory.

Link to comment
Share on other sites

The barcode scanner ITSELF added the {f9} ( the {} means it sends it as a key, not typing an "f" then a "9")
I believe it was a motorola symbol, and through it's setuputility it was able to add a pre- and -post barcode sequence.

This is all on the barcode scanner itself, through it's utility / configuration software! Your scanner may vary.
I set up {F9} and pause 20ms before barcode
then send scanned data
then send {enter}

I would scan "1132845", the scanner itself would send "{F9} <pause 20ms> 1132845{enter}". This only works if the scanner supports it, but once it's set up my scanner would remember the settings, making both the scanner (In HID mode by default) and the software plug-and-play

If you know which barcode scanners you are using, I can help you set up a similar solution, unless you find one of the solutions above more useful :P

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...