pass
    while ble.connected:
        #  sets x and y values for accelerometer x and y values
        #  x and y are swapped for orientation of feather
        y, x, z = lsm6ds33.acceleration

        #  map range of horizontal movement to mouse x movement
        horizontal_mov = simpleio.map_range(steps(x), 1.0, 20.0, -15.0, 15.0)
        #  map range of vertical movement to mouse y movement
        vertical_mov = simpleio.map_range(steps(y), 20.0, 1.0, -15.0, 15.0)
        #  map range of mouse y movement to scrolling
        scroll_dir = simpleio.map_range(vertical_mov, -15.0, 15.0, 3.0, -3.0)

        #  if onboard button is pressed, sends left mouse click
        if not click.value:
            mouse.click(Mouse.LEFT_BUTTON)
            time.sleep(0.2)
        #  if the proximity sensor is covered
        #  scroll the mouse
        if apds9960.proximity > distance:
            mouse.move(wheel=int(scroll_dir))
        #  otherwise move mouse cursor in x and y directions
        else:
            mouse.move(x=int(horizontal_mov))
            mouse.move(y=int(vertical_mov))

        #  debugging print for x and y values
        #  time.monotonic() is used so that the
        #  code is not delayed with time.sleep
        if (clock + 2) < time.monotonic():
            print("x", steps(x))
Esempio n. 2
0
def mouse_config(key_to_be_pressed):
    mouse = Mouse(usb_hid.devices)
    mouse.click(key_to_be_pressed)
Esempio n. 3
0
import usb_hid
import time
from adafruit_circuitplayground.express import cpx
from adafruit_hid.mouse import Mouse
from adafruit_circuitplayground import cp

m = Mouse(usb_hid.devices)
cpx.adjust_touch_threshold(200)
pix = cpx.pixels
pix.brightness = 0.4
while True:
    x, y, z = cpx.acceleration
    for i in range(10):
        print((abs(int(x)) * 10, abs(int(y)) * 10, abs(int(z)) * 10))
        pix[i] = (abs(int(x)) * 10 % 255, abs(int(y)) * 10 % 255,
                  abs(int(z)) * 10 % 255)
    if cpx.switch:
        continue

    cpx.red_led = True
    m.move(5 * int(-x), 5 * int(y), 0)
    if cp.button_a:
        m.click(Mouse.LEFT_BUTTON)

    if cp.button_b:
        m.click(Mouse.RIGHT_BUTTON)
    print(y)
Esempio n. 4
0
D3.direction = Direction.INPUT
D3.pull = Pull.UP

# fourth button
D4 = DigitalInOut(board.D4)
D4.direction = Direction.INPUT
D4.pull = Pull.UP

# loop forever
while True:

    if not D1.value:
        # configure device as  keyboard
        kbd = Keyboard(usb_hid.devices)
        layout = KeyboardLayoutUS(kbd)
        kbd.send(Keycode.SPACE)  # press the SPACEBAR
        time.sleep(debounce_time)  # debounce delay
    if not D2.value:
        # configure device as mouse
        mouse = Mouse(usb_hid.devices)
        mouse.click(Mouse.LEFT_BUTTON)  # press the Left MOUSE Button
        time.sleep(debounce_time)  # debounce delay
    if not D3.value:
        # configure device as mouse
        mouse = Mouse(usb_hid.devices)
        mouse.move(-10)  # move the mouse right 10
    if not D4.value:
        # configure device as mouse
        mouse = Mouse(usb_hid.devices)
        mouse.move(10)  # move the mouse left 10
axe_x = AnalogIn(A4)
axe_y = AnalogIn(A3)
# Mise en place de la broche émulant le bouton gauche de la souris
bouton_gauche = DigitalInOut(A5)
bouton_gauche.direction = Direction.INPUT
bouton_gauche.pull = Pull.UP

# ---------------------------------------
# -------  BOUCLE PRINCIPALE  -----------
# ---------------------------------------
while True:
    # Mesure la valeur numérique des deux axes + mise à l'échelle
    x=map_range(axe_x.value, 0, 65535, 0, 20)
    y=map_range(axe_y.value, 0, 65535, 0, 20)
    # Si le bouton gauche est appuyé alors on émule le clic gauche de la souris
    if bouton_gauche.value is False:
        souris.click(Mouse.LEFT_BUTTON)
    # Si le joystick est à droite, on déplace le curseur d'une unité à droite
    if x > 12.0:
        souris.move(x=1)
    # Si le joystick est à gauche, on déplace le curseur d'une unité à gauche
    if x < 8.0:
        souris.move(x=-1)
    # Si le joystick est vers le haut, on déplace le curseur d'une unité vers le haut
    if y > 12.0:
        souris.move(y=-1)
    # Si le joystick est vers le bas, on déplace le curseur d'une unité vers le bas
    if y < 8.0:
        souris.move(y=1)

Esempio n. 6
0
    # Open program
    if PROGRAM != "NONE":
        time.sleep(.5)
        search_keycodes = (Keycode.WINDOWS, ) if OS == "WINDOWS" else (
            Keycode.COMMAND, Keycode.SPACE)
        kbd.send(*search_keycodes)
        time.sleep(.5)
        USLayout.write(PROGRAM)
        time.sleep(.25)
        kbd.send(Keycode.ENTER)
        time.sleep(2)

    for step in STEPS:
        if "KEYS" in step:
            codes = tuple(special_chars[code]
                          for code in step.split("KEYS")[1].strip().split(' '))
            kbd.send(*codes)
        elif "WAIT" in step:
            sec = step.split(" ")[1]
            time.sleep(float(sec))
        elif "MOUSE" in step:
            x, y = step.split(" ")[1:]
            mouse.move(int(x), int(y))
        elif "CLICK" in step:
            button = step.split(" ")[1].strip()
            mouse.click(mouse_click[button])
        else:
            USLayout.write(step)
            kbd.send(Keycode.ENTER)
        print(step)
Esempio n. 7
0
         uart.write(b'OK')
     except:
         print("ECRIT ERROR")
         uart.write(b'NO')
 if data_string[:5]=="WRITE":
     try:
         k.write(data_string[6:])
         uart.write(b'OK')
     except:
         print("WRITE ERROR")
         uart.write(b'NO')
 # Mouse part
 # MCLIC:button (1,2 or 4)                  ex. MCLIC:1
 if data_string[:5]=="MCLIC":
     try:
         mouse.click(int(data_string[6:]))
         uart.write(b'OK')
     except:
         print("MCLIC ERROR")
         uart.write(b'NO')
 # MMOVE:x,y,wheel                          ex. MMOVE:x=-10,y=2
 if data_string[:5]=="MMOVE":
     try:
         mouse.move(data_string[6:])
         uart.write(b'OK')
     except:
         print("MMOVE ERROR")
         uart.write(b'NO')
 # MPRES:button (1,2 or 4)                  ex. MPRES:2
 if data_string[:5]=="MPRES":
     try:
Esempio n. 8
0
                     elif type(k) is int and k in settings.modifierKeys:
                         modifiersOn.append(
                             k
                         ) if modifiers[k] == 0 else modifiersOn.remove(k)
                         modifiers[k] = not modifiers[k]
                         print("Modifier", k, "is:", modifiers[k])
                     else:
                         keyPress(k, modifiersOn)
         elif a[0] == Mode.MOUSE_MOVE:
             (actionType, x, y, w) = a
             print("MouseMove x=", x, ",y=", y, ",w=", w)
             mouse.move(x, y, w)
         elif a[0] == Mode.MOUSE_CLICK:
             (actionType, button) = a
             print("MouseClick=", button)
             mouse.click(button)
     if (switchCode != lastCode):
         print("NewCode")
         lastCode = switchCode
         codeStartTime = readTime
     else:
         if (readTime > (codeStartTime + modeDelay)):
             print("longPress")
             if (switchCode == modeSwitchCode):
                 numOfModes = len(settings.modes)
                 modeNum = (modeNum + 1) % numOfModes
                 currentMode = settings.modes[modeNum]
                 modeColor = hex2rgb(currentMode.color)
                 dot[0] = modeColor
                 codeStartTime = readTime
 else: