0

Is it possible to pass the result of a python script (a reading from a usb device) directly to where the cursor is active within windows?

Ive been looking for a solution to this problem all weekend and I think I may be phrasing my question wrong or maybe looking in the wrong places. I know that you cannot just pass a result to an active input box in PHP (ive asked this on Friday) and this is a different scenario.

I am very much new to Python and any assistance or direction to a solution would be great. Im not looking for the straight up answer - just the correct direction.

Thanks in advance and happy monday!

EDIT: I found some of this open source and wrote some of it as well... I am getting an EOL while scanning string literal.

I am almost positive it has something to do with the formatting, but I cannot find it. Can someone please take a look at the code and let me know what I might be doing wrong?

import usb.core
import usb.util

VENDOR_ID = 0x0922
PRODUCT_ID = 0x8003

# find the USB device
device = usb.core.find(idVendor=VENDOR_ID,
                   idProduct=PRODUCT_ID)

# use the first/default configuration
device.set_configuration()
# first endpoint
endpoint = device[0][(0,0)][0]

# read a data packet
attempts = 10
data = None
while data is None and attempts > 0:
    try:
        data = device.read(endpoint.bEndpointAddress,
                           endpoint.wMaxPacketSize)
    except usb.core.USBError as e:
        data = None
        if e.args == ('Operation timed out',):
            attempts -= 1
            continue

SendKeysCtypes.SendKeys(data+'{ENTER}’, 0)
Bob K
  • 1
  • 1
  • What OS are you writing this for? – user812786 Jun 12 '17 at 16:39
  • 1
    If I'm understanding this correctly, you may want to look up stuff about sending (or "simulating") keystrokes or mouse events in Python for your OS. Something like [this old question](https://stackoverflow.com/questions/2791839/which-is-the-easiest-way-to-simulate-keyboard-and-mouse-on-python) might be a start? – user812786 Jun 12 '17 at 16:45
  • Hi, thanks for responding. I am writing, or rather the usb device (a scale) will be on a windows 10 machine. I will look at what you sent, thank you. If there is any other information I can provide, please let me know. – Bob K Jun 12 '17 at 16:59
  • Hi @whrrgabl, I just added code but am having an issue with the send key line in that I am getting a EOL While scanning string literal error on the SendKeysCtypes.SendKeys line (the last line). Can you help? – Bob K Jun 12 '17 at 18:57
  • Hm is that exactly the code you have typed in? The close quote looks like it's a "smart quote" version, try retyping it. – user812786 Jun 12 '17 at 19:19

0 Answers0