2

I have the following two Industrial Barcode Scanners-

  1. Datalogic Magellan 800i
  2. Datalogic Gryphon I GBT4400

I want to scan a QRCode which contains a URI and it should open automatically that URI directly in the default browser of the machine.

Right now, the device is properly scanning the QRCode and returns the URI as string. If I keep the focus and cursor on the browser's address bar, the url gets filled over there but this is a very tedious process.

I want to ask is there any thrid-party software available which could detect that the scanned code contains the URI and automatically opens the browser with the scanned URL?

I have been searching for the solution from few days but still didn't got what I want. The barcode device is attached to a windows 8.1 machine.

Can anyone help?

2
  • If you could tell me what software are you using to get the barcode and how it is retuned (in clipboard, dircectly typed out, file...) a Python script should be a simple task.
    – jan
    Commented Mar 9, 2016 at 20:57
  • Hi, right now I am using no software just only the device drivers are installed, when scanned the device returns directly typed out result i.e. the text would be typed where ever the cursor would be currently like if cursor is in any text editor the url would be posted there. Commented Mar 10, 2016 at 10:52

2 Answers 2

2

Since there is still no answer to this question I will post my workaround to the problem.

Steps:

  1. Install Python 2.7 and check the Add python.exe to Path checkbox when installing (Yes. I know this is overkill on the first step.)
  2. Go to the command prompt and type in pip install pyHook (case sensitive). It should say something like "Successfully installed pyHook" after a few moments.
  3. Create a new file and call it yourname.py

Put this script into the file:

# -*- coding: utf-8 -*-

import pyHook
import pythoncom
import re
import webbrowser
endDomains = ".com|.net|.org|.edu|.gov|.mil|.aero|.asia|.biz|.cat|.coop|.info|.int|.jobs|.mobi|.museum|.name|.post|.pro|.tel|.travel".split("|")
chars = ""
def pressed_chars(event):
    global chars
    if event.Ascii:
        char = chr(event.Ascii)    
        if event.Ascii == 3:
            quit()
        else:
            chars += char
            try:
                urls = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', chars)
                print(urls)
            except:
                urls = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', chars)
                print(urls)
            if len(urls) > 0:
                for url in urls:
                    for i in endDomains:
                        if i in url:
                            webbrowser.open_new_tab(url)
                            chars = ""
                            break
proc = pyHook.HookManager()
proc.KeyDown = pressed_chars
proc.HookKeyboard()
pythoncom.PumpMessages()

Now just open the file.

You should see a black window. If you do and it doesn't close it's working.

Now any link that is typed using the keyboard (or the barcode scanner driver) will be automatically opened in the default web browser.

NOTE: These links WILL open:

http://www.google.com
https://www.google.com
http://youtube.com

These links will NOT open:

www.google.com
www.google.com
youtube.com

This is so when you type in a link using the keyboard it is not opened with the web browser (because people do not usualy type in the http:// prefix).

TIP: You can auto-run the script upon startup by putting it into the startup folder.

If you have any problems or anything just leave a comment.

4
  • Hello Janekmuric, thanks for your response, this looks very promising and I will try this, is there anything similar to the above which might the same as this on Mac? Commented Mar 18, 2016 at 10:30
  • @ManikArora Yes. This exact Python script should run on any system where Python 2.7 is installed. You can download Python for Mac using the link I already posted in the answer. Oh, and did you try this? Did it work? I hope it did :)
    – jan
    Commented Mar 19, 2016 at 12:49
  • I don't think it would work on Mac based on these answers - stackoverflow.com/a/21583811/3748701. However it did worked on windows. So I am marking your answer as accepted as question was originally for windows only. Commented Mar 21, 2016 at 6:00
  • I dont suppose you'd be able to help me, Im trying to modify your code and I've run into a problem that I dont understand: stackoverflow.com/questions/43908206/…
    – Chud37
    Commented May 11, 2017 at 6:52
2

I had a few problems with the install, and getting the script to run so I thought I'd post what I did differently that worked for me and why.

  1. scanner: www.amazon.com/gp/product/B0159HAN96/ref=oh_aui_detailpage_o04_s00?ie=UTF8&psc=1
  2. Python installer to download: http://www.activestate.com/activepython/downloads
  3. pyHook installer required. Found here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyhook
  4. Make sure to download the right 32-bit or 64-bit installers. For pyHook, you want the cp27 version.
  5. Run the ActivePython installer.
  6. Then open a CMD window, type in “pip install + [location of pyhook installer]”
  7. I found it easiest to put the .whl file in the Python27 folder on the C drive. So my CMD prompt instructions were: pip install c:\Python27\pyHook-1.5.1-cp27-none-win_amd64.whl
  8. Then you need to place this script in notepad and save out as a .py file. It will have a Blue & Yellow Python Icon on it if it saved correctly. Place this script in notepad:

[code]

# -*- coding: utf-8 -*-

import pyHook
import pythoncom
import re
import webbrowser
endDomains = "1/|2/|3/4/|5/|6/|7/|8/|9/|0/|-1|-2|-3|-4|-5|-6|-7|-8|-9|-0".split("|")
chars = ""
def pressed_chars(event):
    global chars
    if event.Ascii:
        char = chr(event.Ascii)    
        if event.Ascii == 3:
            quit()
        else:
            chars += char
            try:
                urls = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', chars)
                print(urls)
            except:
                urls = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', chars)
                print(urls)
            if len(urls) > 0:
                for url in urls:
                    for i in endDomains:
                        if i in url:
                            b = webbrowser.get('windows-default')
                            b.open_new_tab(url)
                            chars = ""
                            break
proc = pyHook.HookManager()
proc.KeyDown = pressed_chars
proc.HookKeyboard()
pythoncom.PumpMessages()
  1. Open the .py file and it should open a CMD window that stays up.
  2. Tip #1: the script has an “endDomains” array list. I changed it to suit the URL's that I was making. They all ended in either #/ or -# and I didn't want the script to stop at .com or .net.
  3. Tip #2: I also added a “b = web browser.get()” variable. This tells it what web browser to open the URL in. Internet explorer can be crabby about opening a direct typed URL, so I found that having Firefox set as the default browser in the computer fixed that. That variable is supposed to be able to designate a specific browser by program name, but that wasn’t working for me, it kept erroring out.
3
  • thanks @alith, very nice and beautiful answer with steps Commented Aug 8, 2016 at 3:52
  • thank you! @ManikArora not new to coding, but this is my first dive into Python so it took me a bit to work it out. Normally I work in web dev stuff. I would like to develop it further though. It would be a nice improvement to limit it to inputs from a specific device (ie. the scanner), so it's not logging all the keyboard inputs. that does seem to make it hiccup sometimes.
    – Alith7
    Commented Aug 8, 2016 at 16:30
  • Thank you, but why does the above installers work compared to ones previously mentioned by Janekmuric? I couldnt get pyHook to work with his method.
    – Chud37
    Commented May 10, 2017 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.