コード例 #1
0
ファイル: test_keyboard.py プロジェクト: chelpis/foohid-py
keyboard = (0x05, 0x01, 0x09, 0x06, 0xa1, 0x01, 0x05, 0x07, 0x19, 0xe0, 0x29,
            0xe7, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02,
            0x95, 0x01, 0x75, 0x08, 0x81, 0x01, 0x95, 0x05, 0x75, 0x01, 0x05,
            0x08, 0x19, 0x01, 0x29, 0x05, 0x91, 0x02, 0x95, 0x01, 0x75, 0x03,
            0x91, 0x01, 0x95, 0x06, 0x75, 0x08, 0x15, 0x00, 0x25, 0x65, 0x05,
            0x07, 0x19, 0x00, 0x29, 0x65, 0x81, 0x00, 0x09, 0x00, 0x75, 0x08,
            0x95, 0x01, 0x15, 0x00, 0x25, 0x7f, 0xb1, 0x02, 0xc0)

try:
    foohid.destroy("FooHID simple keyboard")
except:
    pass

foohid.create("FooHID simple keyboard",
              struct.pack('{0}B'.format(len(keyboard)), *keyboard), "SN 123",
              2, 3)

try:
    while True:
        # press "a" key
        foohid.send("FooHID simple keyboard",
                    struct.pack('8B', 0, 0, 4, 0, 0, 0, 0, 0))
        time.sleep(0.1)
        foohid.send("FooHID simple keyboard",
                    struct.pack('8B', 0, 0, 0, 0, 0, 0, 0, 0))
        time.sleep(0.5)
except KeyboardInterrupt:
    # make sure key is unpressed before exiting
    foohid.send("FooHID simple keyboard",
                struct.pack('8B', 0, 0, 0, 0, 0, 0, 0, 0))
    foohid.destroy("FooHID simple keyboard")
コード例 #2
0
import foohid
import struct
import random
import time

joypad = (0x05, 0x01, 0x09, 0x05, 0xa1, 0x01, 0xa1, 0x00, 0x05, 0x09, 0x19,
          0x01, 0x29, 0x10, 0x15, 0x00, 0x25, 0x01, 0x95, 0x10, 0x75, 0x01,
          0x81, 0x02, 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x09, 0x32, 0x09,
          0x33, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08, 0x95, 0x04, 0x81, 0x02,
          0xc0, 0xc0)

try:
    foohid.destroy("FooHID simple joypad")
except:
    pass
foohid.create("FooHID simple joypad",
              struct.pack('{0}B'.format(len(joypad)), *joypad), "SN 123", 2, 3)

try:
    while True:
        x = random.randrange(0, 255)
        y = random.randrange(0, 255)
        z = random.randrange(0, 255)
        rx = random.randrange(0, 255)
        foohid.send("FooHID simple joypad", struct.pack('H4B', 0, x, y, z, rx))
        time.sleep(1)
except KeyboardInterrupt:
    foohid.destroy("FooHID simple joypad")
コード例 #3
0
ファイル: test_mouse.py プロジェクト: chelpis/foohid-py
import foohid
import struct
import random
import time

mouse = (0x05, 0x01, 0x09, 0x02, 0xa1, 0x01, 0x09, 0x01, 0xa1, 0x00, 0x05,
         0x09, 0x19, 0x01, 0x29, 0x03, 0x15, 0x00, 0x25, 0x01, 0x95, 0x03,
         0x75, 0x01, 0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x03, 0x05,
         0x01, 0x09, 0x30, 0x09, 0x31, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08,
         0x95, 0x02, 0x81, 0x06, 0xc0, 0xc0)

try:
    foohid.destroy("FooHID simple mouse")
except:
    pass
foohid.create("FooHID simple mouse",
              struct.pack('{0}B'.format(len(mouse)), *mouse), "SN 123", 2, 3)

try:
    while True:
        x = random.randrange(0, 255)
        y = random.randrange(0, 255)
        foohid.send("FooHID simple mouse", struct.pack('3B', 0, x, y))
        time.sleep(1)
except KeyboardInterrupt:
    foohid.destroy("FooHID simple mouse")