コード例 #1
0
import digitalio
import busio
import adafruit_lis3dh
import usb_hid
from adafruit_hid.mouse import Mouse

killswitch = digitalio.DigitalInOut(board.SLIDE_SWITCH)
killswitch.direction = digitalio.Direction.INPUT
killswitch.pull = digitalio.Pull.UP

lmb = digitalio.DigitalInOut(board.BUTTON_A)
lmb.direction = digitalio.Direction.INPUT
lmb.pull = digitalio.Pull.DOWN
lmb_pre = lmb.value

rmb = digitalio.DigitalInOut(board.BUTTON_B)
rmb.direction = digitalio.Direction.INPUT
rmb.pull = digitalio.Pull.DOWN
rmb_pre = rmb.value

mouse = Mouse(usb_hid.devices)

while True:

    if killswitch.value:

        if rmb.value:
            mouse.move(0, 0, 1)

        if lmb.value:
            mouse.move(0, 0, -1)
コード例 #2
0
class PiperCommandCenter:
    def __init__(self,
                 joy_x_pin=board.A4,
                 joy_y_pin=board.A3,
                 joy_z_pin=board.D2,
                 joy_gnd_pin=board.A5,
                 dpad_l_pin=board.D3,
                 dpad_r_pin=board.D4,
                 dpad_u_pin=board.D1,
                 dpad_d_pin=board.D0,
                 mc_top_pin=board.SCK,
                 mc_middle_pin=board.MOSI,
                 mc_bottom_pin=board.MISO,
                 outputScale=20.0,
                 deadbandCutoff=0.1,
                 weight=0.2):
        self.x_axis = PiperJoystickAxis(joy_x_pin,
                                        outputScale=outputScale,
                                        deadbandCutoff=deadbandCutoff,
                                        weight=weight)
        self.y_axis = PiperJoystickAxis(joy_y_pin,
                                        outputScale=outputScale,
                                        deadbandCutoff=deadbandCutoff,
                                        weight=weight)
        self.joy_z = PiperJoystickZ(joy_z_pin)
        self.dpad = PiperDpad(dpad_l_pin, dpad_r_pin, dpad_u_pin, dpad_d_pin)
        self.minecraftbuttons = PiperMineCraftButtons(mc_top_pin,
                                                      mc_middle_pin,
                                                      mc_bottom_pin)

        # Drive pin low if requested for easier joystick wiring
        if joy_gnd_pin is not None:
            # Provide a ground for the joystick - this is to facilitate
            # easier wiring
            self.joystick_gnd = DigitalInOut(joy_gnd_pin)
            self.joystick_gnd.direction = Direction.OUTPUT
            self.joystick_gnd.value = 0

        self.keyboard = Keyboard(usb_hid.devices)
        self.keyboard_layout = KeyboardLayoutUS(
            self.keyboard)  # Change for non-US
        self.mouse = Mouse(usb_hid.devices)

        # State
        #
        self.state = _UNWIRED
        self.timer = time.monotonic()
        self.last_mouse_wheel = time.monotonic()
        self.last_mouse = time.monotonic()
        self.dotstar_led = adafruit_dotstar.DotStar(board.APA102_SCK,
                                                    board.APA102_MOSI, 1)
        self.dotstar_led.brightness = 0.2
        self.up_pressed = False
        self.down_pressed = False
        self.left_pressed = False
        self.right_pressed = False
        self.mc_mode = _MC_DEFAULT
        self.mc_flyingdown_req = False
        self.mc_sprinting_req = False
        self.mc_crouching_req = False
        self.mc_utility_req = False

#    def process_repl_cmds(self):
#        # Assume that the command will be pasted, because input()
#        # will block until end of line
#        #
#        if supervisor.runtime.serial_bytes_available:
#            cmd = input()
#            exec(cmd)

    def releaseJoystickHID(self):
        self.mouse.release(Mouse.LEFT_BUTTON)
        self.mouse.release(Mouse.RIGHT_BUTTON)

    def releaseKeyboardHID(self):
        self.keyboard.release(Keycode.UP_ARROW)
        self.keyboard.release(Keycode.DOWN_ARROW)
        self.keyboard.release(Keycode.LEFT_ARROW)
        self.keyboard.release(Keycode.RIGHT_ARROW)
        self.keyboard.release(Keycode.SPACE)
        self.keyboard.release(Keycode.X)
        self.keyboard.release(Keycode.Z)
        self.keyboard.release(Keycode.C)

    def releaseMinecraftHID(self):
        self.mouse.release(Mouse.LEFT_BUTTON)
        self.mouse.release(Mouse.MIDDLE_BUTTON)
        self.mouse.release(Mouse.RIGHT_BUTTON)

        self.keyboard.release(Keycode.A)
        self.keyboard.release(Keycode.CONTROL)
        self.keyboard.release(Keycode.D)
        self.keyboard.release(Keycode.E)
        self.keyboard.release(Keycode.ESCAPE)
        self.keyboard.release(Keycode.F5)
        self.keyboard.release(Keycode.LEFT_SHIFT)
        self.keyboard.release(Keycode.Q)
        self.keyboard.release(Keycode.S)
        self.keyboard.release(Keycode.SPACE)
        self.keyboard.release(Keycode.W)

    def process(self):
        #self.process_repl_cmds()

        # Call the debouncing library frequently
        self.joy_z.update()
        self.dpad.update()
        self.minecraftbuttons.update()

        dx = self.x_axis.readJoystickAxis()
        dy = self.y_axis.readJoystickAxis()

        # Command Center State Machine
        #
        if self.state == _UNWIRED:
            self.dotstar_led[0] = ((time.monotonic_ns() >> 23) % 256, 0, 0)
            if dx == 0 and dy == 0:
                self.state = _WAITING
                self.timer = time.monotonic()
        elif self.state == _WAITING:
            self.dotstar_led[0] = ((time.monotonic_ns() >> 23) % 256, 0, 0)
            if dx != 0 or dy != 0:
                self.state = _UNWIRED
            else:
                if time.monotonic() - self.timer > 0.5:
                    self.state = _JOYSTICK
        elif self.state == _JOYSTICK:
            self.dotstar_led[0] = (0, 255, 0)
            if self.joy_z.zPressed():
                self.timer = time.monotonic()
                self.state = _JWAITING
        elif self.state == _JWAITING:
            if not self.joy_z.zPressed():
                self.state = _JOYSTICK
            else:
                if time.monotonic() - self.timer > 1.0:
                    self.state = _KEYBOARD
                    self.releaseJoystickHID()
        elif self.state == _KEYBOARD:
            self.dotstar_led[0] = (0, 0, 255)
            if self.joy_z.zPressed(
            ) and not self.minecraftbuttons.bottomPressed():
                self.timer = time.monotonic()
                self.state = _KWAITING_TO_J
            elif self.joy_z.zPressed() and self.minecraftbuttons.bottomPressed(
            ):
                self.timer = time.monotonic()
                self.state = _KWAITING_TO_MC
        elif self.state == _KWAITING_TO_J:
            if not self.joy_z.zPressed(
            ) or self.minecraftbuttons.bottomPressed():
                self.state = _KEYBOARD
                self.up_pressed = False
                self.down_pressed = False
                self.left_pressed = False
                self.right_pressed = False
            else:
                if time.monotonic() - self.timer > 1.0:
                    self.state = _JOYSTICK
                    self.releaseKeyboardHID()
        elif self.state == _KWAITING_TO_MC:
            if not self.joy_z.zPressed(
            ) or not self.minecraftbuttons.bottomPressed():
                self.state = _KEYBOARD
                self.up_pressed = False
                self.down_pressed = False
                self.left_pressed = False
                self.right_pressed = False
            else:
                if time.monotonic() - self.timer > 1.0:
                    self.state = _MINECRAFT
                    self.releaseKeyboardHID()
        elif self.state == _MINECRAFT:
            if self.mc_mode == _MC_DEFAULT:
                self.dotstar_led[0] = (0, 255, 255)  # cyan
            elif self.mc_mode == _MC_FLYINGDOWN:
                self.dotstar_led[0] = (255, 0, 255)  # magenta
            elif self.mc_mode == _MC_SPRINTING:
                self.dotstar_led[0] = (255, 128, 128)  # pink
            elif self.mc_mode == _MC_CROUCHING:
                self.dotstar_led[0] = (255, 165, 0)  # orange
            elif self.mc_mode == _MC_UTILITY:
                self.dotstar_led[0] = (255, 255, 0)  # yellow

            if self.joy_z.zPressed() and self.dpad.upPressed(
            ) and self.dpad.downPressed() and self.dpad.leftPressed(
            ) and self.dpad.rightPressed():
                self.timer = time.monotonic()
                self.state = _MWAITING
        elif self.state == _MWAITING:
            if not self.joy_z.zPressed() or not self.dpad.upPressed(
            ) or not self.dpad.downPressed() or not self.dpad.leftPressed(
            ) or not self.dpad.rightPressed():
                self.state = _MINECRAFT
            else:
                if time.monotonic() - self.timer > 1.0:
                    self.state = _JOYSTICK
                    self.releaseMinecraftHID()

        # Command Center Joystick Handling
        #
        if self.state == _JOYSTICK or self.state == _JWAITING:
            # Determine mouse wheel direction
            #
            dwheel = 0
            if self.dpad.upPressed():
                dwheel = -1
            elif self.dpad.downPressed():
                dwheel = 1

            # Initial quick and dirty mouse movement pacing
            #
            if time.monotonic() - self.last_mouse > 0.005:
                self.last_mouse = time.monotonic()
                self.mouse.move(x=dx, y=dy)

            # Initial quick and dirty mouse scroll wheel pacing
            #
            if time.monotonic() - self.last_mouse_wheel > 0.1:
                self.last_mouse_wheel = time.monotonic()
                self.mouse.move(wheel=dwheel)

            if self.dpad.leftPressedEvent():
                self.mouse.press(Mouse.LEFT_BUTTON)
            elif self.dpad.leftReleasedEvent():
                self.mouse.release(Mouse.LEFT_BUTTON)

            if self.dpad.rightPressedEvent():
                self.mouse.press(Mouse.RIGHT_BUTTON)
            elif self.dpad.rightReleasedEvent():
                self.mouse.release(Mouse.RIGHT_BUTTON)

        # Command Center Keyboard Handling
        #
        if self.state == _KEYBOARD or self.state == _KWAITING_TO_J or self.state == _KWAITING_TO_MC:
            if self.dpad.upPressedEvent():
                self.keyboard.press(Keycode.SPACE)
            elif self.dpad.upReleasedEvent():
                self.keyboard.release(Keycode.SPACE)

            if self.dpad.downPressedEvent():
                self.keyboard.press(Keycode.X)
            elif self.dpad.downReleasedEvent():
                self.keyboard.release(Keycode.X)

            if self.dpad.leftPressedEvent():
                self.keyboard.press(Keycode.Z)
            elif self.dpad.leftReleasedEvent():
                self.keyboard.release(Keycode.Z)

            if self.dpad.rightPressedEvent():
                self.keyboard.press(Keycode.C)
            elif self.dpad.rightReleasedEvent():
                self.keyboard.release(Keycode.C)

            if dx == 0:
                if self.left_pressed:
                    self.left_pressed = False
                    self.keyboard.release(Keycode.LEFT_ARROW)
                if self.right_pressed:
                    self.right_pressed = False
                    self.keyboard.release(Keycode.RIGHT_ARROW)
            elif dx > 0:
                if self.left_pressed:
                    self.left_pressed = False
                    self.keyboard.release(Keycode.LEFT_ARROW)
                if not self.right_pressed:
                    self.right_pressed = True
                    self.keyboard.press(Keycode.RIGHT_ARROW)
            elif dx < 0:
                if not self.left_pressed:
                    self.left_pressed = True
                    self.keyboard.press(Keycode.LEFT_ARROW)
                if self.right_pressed:
                    self.right_pressed = False
                    self.keyboard.release(Keycode.RIGHT_ARROW)

            if dy == 0:
                if self.up_pressed:
                    self.up_pressed = False
                    self.keyboard.release(Keycode.UP_ARROW)
                if self.down_pressed:
                    self.down_pressed = False
                    self.keyboard.release(Keycode.DOWN_ARROW)
            elif dy < 0:
                if not self.up_pressed:
                    self.up_pressed = True
                    self.keyboard.press(Keycode.UP_ARROW)
                if self.down_pressed:
                    self.down_pressed = False
                    self.keyboard.release(Keycode.DOWN_ARROW)
            elif dy > 0:
                if self.up_pressed:
                    self.up_pressed = False
                    self.keyboard.release(Keycode.UP_ARROW)
                if not self.down_pressed:
                    self.down_pressed = True
                    self.keyboard.press(Keycode.DOWN_ARROW)

        # Command Center Minecraft Handling
        #
        if self.state == _MINECRAFT:
            # Modifier button
            #
            if self.minecraftbuttons.bottomPressed():
                if self.joy_z.zPressedEvent():
                    self.mc_flyingdown_req = True
                    self.mc_sprinting_req = False
                    self.mc_crouching_req = False
                    self.mc_utility_req = False
                elif self.dpad.upPressedEvent():
                    self.mc_flyingdown_req = False
                    self.mc_sprinting_req = True
                    self.mc_crouching_req = False
                    self.mc_utility_req = False
                elif self.dpad.downPressedEvent():
                    self.mc_flyingdown_req = False
                    self.mc_sprinting_req = False
                    self.mc_crouching_req = True
                    self.mc_utility_req = False
                elif self.dpad.leftPressedEvent():
                    self.mc_flyingdown_req = False
                    self.mc_sprinting_req = False
                    self.mc_crouching_req = False
                    self.mc_utility_req = True

            if self.minecraftbuttons.bottomReleasedEvent():
                self.releaseMinecraftHID()
                if self.mc_flyingdown_req:
                    self.mc_mode = _MC_FLYINGDOWN
                    self.mc_flyingdown_req = False
                elif self.mc_sprinting_req:
                    self.mc_mode = _MC_SPRINTING
                    self.mc_sprinting_req = False
                    self.keyboard.press(Keycode.CONTROL)
                elif self.mc_crouching_req:
                    self.mc_mode = _MC_CROUCHING
                    self.mc_crouching_req = False
                    self.keyboard.press(Keycode.LEFT_SHIFT)
                elif self.mc_utility_req:
                    self.mc_mode = _MC_UTILITY
                    self.mc_utility_req = False
                else:
                    self.mc_mode = _MC_DEFAULT

            # Joystick functionality for mouse movement is always active
            #
            # Mouse movement is paced - may need to adjust
            #
            if time.monotonic() - self.last_mouse > 0.005:
                self.last_mouse = time.monotonic()
                self.mouse.move(x=dx, y=dy)

            # Top and bottom buttons changed by mod key in default mode
            #
            if self.mc_mode == _MC_DEFAULT and self.minecraftbuttons.bottomPressed(
            ):
                if self.minecraftbuttons.topPressedEvent():
                    self.keyboard.press(Keycode.Q)
                elif self.minecraftbuttons.topReleasedEvent():
                    self.keyboard.release(Keycode.Q)

                if self.minecraftbuttons.middlePressedEvent():
                    self.mouse.press(Mouse.MIDDLE_BUTTON)
                elif self.minecraftbuttons.middleReleasedEvent():
                    self.mouse.release(Mouse.MIDDLE_BUTTON)
            else:
                if self.minecraftbuttons.topPressedEvent():
                    self.mouse.press(Mouse.LEFT_BUTTON)
                elif self.minecraftbuttons.topReleasedEvent():
                    self.mouse.release(Mouse.LEFT_BUTTON)

                if self.minecraftbuttons.middlePressedEvent():
                    self.mouse.press(Mouse.RIGHT_BUTTON)
                elif self.minecraftbuttons.middleReleasedEvent():
                    self.mouse.release(Mouse.RIGHT_BUTTON)

            # Don't generate key presses for buttons if modifier key is pressed
            #
            if not self.minecraftbuttons.bottomPressed():
                # Joystick button changes based on minecraft mode
                #
                if self.joy_z.zPressedEvent():
                    self.keyboard.press(_MC_JOYSTICK_Z[self.mc_mode])
                elif self.joy_z.zReleasedEvent():
                    self.keyboard.release(_MC_JOYSTICK_Z[self.mc_mode])

                # DPAD buttons special in utility mode
                #
                if self.mc_mode == _MC_UTILITY:
                    if self.dpad.upPressedEvent():
                        self.mouse.move(wheel=-1)

                    if self.dpad.downPressedEvent():
                        self.mouse.move(wheel=1)

                    if self.dpad.leftPressedEvent():
                        self.keyboard.press(Keycode.E)
                    elif self.dpad.leftReleasedEvent():
                        self.keyboard.release(Keycode.E)

                    if self.dpad.rightPressedEvent():
                        self.keyboard.press(Keycode.ESCAPE)
                    elif self.dpad.rightReleasedEvent():
                        self.keyboard.release(Keycode.ESCAPE)
                else:
                    if self.dpad.upPressedEvent():
                        self.keyboard.press(Keycode.W)
                    elif self.dpad.upReleasedEvent():
                        self.keyboard.release(Keycode.W)

                    if self.dpad.downPressedEvent():
                        self.keyboard.press(Keycode.S)
                    elif self.dpad.downReleasedEvent():
                        self.keyboard.release(Keycode.S)

                    if self.dpad.leftPressedEvent():
                        self.keyboard.press(Keycode.A)
                    elif self.dpad.leftReleasedEvent():
                        self.keyboard.release(Keycode.A)

                    if self.dpad.rightPressedEvent():
                        self.keyboard.press(Keycode.D)
                    elif self.dpad.rightReleasedEvent():
                        self.keyboard.release(Keycode.D)
コード例 #3
0
ファイル: CP_1.py プロジェクト: MGlaab/CP_Access_Key-Mouse
def mouse_config_move_y(y_distance):
    mouse = Mouse(usb_hid.devices)
    mouse.move(x = 0, y = y_distance)
コード例 #4
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)
コード例 #5
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
コード例 #6
0
def steps(axis):
    """ Maps the potentiometer voltage range to 0-20 """
    return round((axis - pot_min) / step)


while True:
    x = get_voltage(x_axis)
    y = get_voltage(y_axis)

    if select.value is False:
        mouse.click(Mouse.LEFT_BUTTON)
        time.sleep(0.2)  # Debounce delay

    if steps(x) > 11.0:
        # print(steps(x))
        mouse.move(x=1)
    if steps(x) < 9.0:
        # print(steps(x))
        mouse.move(x=-1)

    if steps(x) > 19.0:
        # print(steps(x))
        mouse.move(x=8)
    if steps(x) < 1.0:
        # print(steps(x))
        mouse.move(x=-8)

    if steps(y) > 11.0:
        # print(steps(y))
        mouse.move(y=-1)
    if steps(y) < 9.0:
コード例 #7
0
import time
import board
import usb_hid
from adafruit_hid.mouse import Mouse
 
mouse = Mouse(usb_hid.devices)
y = 5
while True :
	mouse.move(0,y)
	y = y * -1
	time.sleep(5)
コード例 #8
0
ファイル: main.py プロジェクト: nireson/desktop-switcher
        time.sleep(0.1)
    if not b2.value:
        bD(2)
        osChoice = 1
        time.sleep(0.1)
    if not b3.value:
        bD(3)
        osChoice = 2
        time.sleep(0.1)

    position = encoder.position

    ## mouse scroll
    if not encClick.value:
        if position < last_position:
            m.move(wheel=1)
            bD(1)
            last_position = position
        if position > last_position:
            m.move(wheel=-1)
            bD(1)
            last_position = position

    ## switch desktops when pressed
    if osChoice == 0 and encClick.value:
        if position < last_position:
            kbd.send(Keycode.GUI, Keycode.CONTROL, Keycode.LEFT_ARROW)
            bD(1)
            last_position = position
        if position > last_position:
            kbd.send(Keycode.GUI, Keycode.CONTROL, Keycode.RIGHT_ARROW)
コード例 #9
0
mouse = Mouse(usb_hid.devices)

i2c = busio.I2C(board.SCL, board.SDA)
apds = APDS9960(i2c)
apds.enable_proximity = True
apds.enable_gesture = True
"""default gesture_proximity_threshold = 50 (range 0-255)"""
apds.gesture_proximity_threshold = 0
"""default gesture_gain = 2 (range 0-3)"""
apds.gesture_gain = 3
"""default gesture_fifo_threshold = 1 (range 0-3)"""
apds.gesture_fifo_threshold = 1
"""default gesture_dimensions = 1 (range 0-3)"""
apds.gesture_dimensions = 0
"""default rotation = 0 (possible, 0, 90, 180, 270)
90 sets green led to UP"""
apds.rotation = 90

UP = 1
DOWN = 2
LEFT = 3
RIGHT = 4

while True:
    gesture = apds.gesture()

    if killswitch.value:
        if gesture == UP:
            mouse.move(0, 0, -3)
        elif gesture == DOWN:
            mouse.move(0, 0, 3)
コード例 #10
0
# Fonction permettant de déplacer le curseur sur de nouvelles coordonnées en cliquant gauche ou pas
def trace(Depl_X,Depl_Y,BOUTON) :
    # Si le 3ème paramètre est 'C' alors on émule un clic sur le bouton gauche de la souris
    # sinon on relâche l'ensemble des boutons
    if (BOUTON == 'C') :
        souris.press(Mouse.LEFT_BUTTON)
    else :
        souris.release_all()
    # On déplace le curseur via les déplacements relatifs Depl_X et Depl_Y
    souris.move(x=Depl_X, y=Depl_Y)

# On trace le dessin en prenant chaque coordonnée dans le tuple
for coordonnee in dessin :
    trace(coordonnee[0],coordonnee[1],coordonnee[2])
    # pause pour donner l'impression d'un dessin fait à la main
    sleep(0.1)

# Relâche le bouton de la souris et ramène le curseur à gauche sous le dessin précédent
souris.release_all()
souris.move(x=-((6*L)+(5*E)),y=2*H)
# Emule l'appui sur le bouton gauche de la souris puis trace un sinus pour souligner
souris.press(Mouse.LEFT_BUTTON)
for i in range (2*180) :
    souris.move(x=1, y=int(10*sin(i)))

# Emule le relâchement de tous les boutons de la souris
souris.release_all()

print("fin")
コード例 #11
0
# move your mouse cursor with the onboard accelerometer
# works with CPX and CPB, copy adafuit_hid to /lib

import board
import time
import digitalio
import busio
import adafruit_lis3dh
import usb_hid
from adafruit_hid.mouse import Mouse

i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1)

mouse = Mouse(usb_hid.devices)

while True:
    x, y, z = lis3dh.acceleration

    if x > 2 or x < -2:
        mouse.move(x=int(-x))

    if y > 2 or y < -2:
        mouse.move(y=int(y))

    time.sleep(0.01)
コード例 #12
0
ファイル: code.py プロジェクト: beboxos/ESPwner
     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:
         mouse.press(int(data_string[6:]))
         uart.write(b'OK')
     except:
         print("MPRES ERROR")
         uart.write(b'NO')
 # MRLEA:button (1,2 or 4)                  ex. MRLEA:2
 if data_string[:5]=="MRLEA":
     try:
コード例 #13
0
import board
import nunchuk
from adafruit_hid.mouse import Mouse

STEP = 5
m = Mouse()
nc = nunchuk.Nunchuk(board.I2C())

while True:
    x, y = nc.joystick
    if x < 100:
        m.move(-STEP, 0, 0)
    if x > 150:
        m.move( STEP, 0, 0)
    if y < 100:
        m.move( 0, STEP, 0)
    if y > 150:
        m.move( 0,-STEP, 0)
    if nc.button_Z:
        m.click(Mouse.LEFT_BUTTON)
    if nc.button_C:
        m.click(Mouse.RIGHT_BUTTON)
コード例 #14
0
from adafruit_hid.mouse import Mouse
from bma250 import BMA250

mouse = Mouse()
bma250 = BMA250()

while True:
    if bma250.xaccel > 40:
        mouse.move(x=1)
    if bma250.xaccel < -40:
        mouse.move(x=-1)
    if bma250.yaccel > 40:
        mouse.move(y=1)
    if bma250.yaccel < -40:
        mouse.move(y=-1)
コード例 #15
0
btn2 = DigitalInOut(board.GP17)
btn2.direction = Direction.INPUT

mouse = Mouse(usb_hid.devices)

prev_btn1 = False
prev_btn2 = False

while True:
    x = int((((int(stickX.value / 100) - 170) / (480 - 170)) - 0.5) * 255)
    y = int((((int(stickY.value / 100) - 170) / (490 - 170)) - 0.5) * 255) * -1

    # print(stickX.value, stickY.value, x, y, btn1.value, btn2.value)
    print(stickX.value, stickY.value, x, y)

    mouse.move(x, y)

    buttons = 0
    buttons_released = 0
    press_flg = False
    release_flg = False
    if not btn1.value:  #Press
        if not prev_btn1:
            buttons = buttons | Mouse.LEFT_BUTTON
            press_flg = True
        prev_btn1 = True
    else:
        if prev_btn1:
            buttons_released = buttons_released | Mouse.LEFT_BUTTON
            release_flg = True
        prev_btn1 = False
コード例 #16
0
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)

コード例 #17
0
ファイル: code.py プロジェクト: bsmith76s/PicoMouseJiggler
import time
import usb_hid
from adafruit_hid.mouse import Mouse
import board
import digitalio

mouse = Mouse(usb_hid.devices)

led = digitalio.DigitalInOut(board.GP25)
led.direction = digitalio.Direction.OUTPUT

led.value = False
time.sleep(5)

while True:
    led.value = True
    mouse.move(x=100)
    led.value = False
    time.sleep(0.5)
    led.value = True
    mouse.move(x=-100)
    led.value = False
    time.sleep(0.5)
コード例 #18
0
import board
import adafruit_nunchuk
from adafruit_hid.mouse import Mouse

THRESHOLD = 10

m = Mouse()
nc = adafruit_nunchuk.Nunchuk(board.I2C())

while True:
    x, y = nc.joystick
    x = (x - 128) // 2
    y = (128 - y) // 2
    if abs(x) > THRESHOLD:
        m.move(x, 0, 0)
    if abs(y) > THRESHOLD:
        m.move(0, y, 0)
    if nc.button_Z:
        m.click(Mouse.LEFT_BUTTON)
    if nc.button_C:
        m.click(Mouse.RIGHT_BUTTON)
コード例 #19
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)
コード例 #20
0
import time
import usb_hid
from adafruit_hid.mouse import Mouse
 
mouse = Mouse(usb_hid.devices)

while True: 
    mouse.move(x=20)
    time.sleep(2)
    mouse.move(x=-20)
    time.sleep(5)
    print("jiggle")
コード例 #21
0
import time
import usb_hid
from adafruit_hid.mouse import Mouse
import board
import digitalio as digitalIO

mouse = Mouse(usb_hid.devices)
led = digitalIO.DigitalInOut(board.GP25)
led.direction = digitalIO.Direction.OUTPUT

led.value = False
time.sleep(5)
mouse.move(y=400)

while True:
    click = 500
    while click > 0:
        led.value = True
        mouse.click(Mouse.LEFT_BUTTON)
        time.sleep(0.01)
        click = click - 1
    led.value = False
    time.sleep(60)
コード例 #22
0
ファイル: CP_1.py プロジェクト: MGlaab/CP_Access_Key-Mouse
def mouse_config_move_x(x_distance):
    mouse = Mouse(usb_hid.devices)
    mouse.move(x = x_distance, y = 0)
コード例 #23
0
import time
import board
import digitalio
import usb_hid
from adafruit_hid.mouse import Mouse

mouse = Mouse(usb_hid.devices)

# define buttons. these can be any physical switches/buttons, but the values
# here work out-of-the-box with a CircuitPlayground Express' A and B buttons.
up = digitalio.DigitalInOut(board.D4)
up.direction = digitalio.Direction.INPUT
up.pull = digitalio.Pull.DOWN

down = digitalio.DigitalInOut(board.D5)
down.direction = digitalio.Direction.INPUT
down.pull = digitalio.Pull.DOWN

while True:
    # scroll up one unit (varies with host/OS)
    if up.value:
        mouse.move(wheel=1)

    # scroll down one unit (varies with host/OS)
    elif down.value:
        mouse.move(wheel=-1)

    time.sleep(0.1)
コード例 #24
0
        layout.write('789\n')
        # Type symbols followed by tab.
        layout.write('!?_*\t')
        # Type lowercase 'x'.
        kbd.send(Keycode.X)
        # Type capital 'Y'.
        kbd.send(Keycode.SHIFT, Keycode.Y)

    if not btn2.value:
        # Debounce
        time.sleep(0.3)
        while not btn2.value:
            pass
        # Toggle mouse wheel up/down by one unit
        if direction:
            mouse.move(wheel=1)
            direction = False
        else:
            mouse.move(wheel=-1)
            direction = True

    if not btn3.value:
        # Debounce
        time.sleep(0.3)
        while not btn3.value:
            pass
        mouse.move(x=60)
        mouse.move(y=-25)

    # Blink built-in LED on Pi Pico
    led.value = not led.value
コード例 #25
0
import time

#Don't want anyone to spot the malicious device!
dot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0)
dot.show()

kbd = Keyboard()
mouse = Mouse()

#list of random evil key presses we might make
keys = [Keycode.TAB, Keycode.LEFT_BRACKET, Keycode.A, Keycode.ZERO]
maxMouseMove = 127
minMouseMove = -127

#Time in seconds to wait until next attack
maxInterval = 600
minInterval = 15

while True:
    random_key = keys[random.randint(0,len(keys))]
    kbd.press(random_key)

    dx = random.randint(minMouseMove, maxMouseMove)
    dy = random.randint(minMouseMove, maxMouseMove)

    mouse.move(x=dx, y=dy)

    print("heeheehee")

    time.sleep(random.randint(minInterval, maxInterval)
コード例 #26
0
from adafruit_circuitplayground.express import cpx
from adafruit_hid.mouse import Mouse

m = Mouse()
cpx.adjust_touch_threshold(200)

while True:
    if cpx.touch_A4:
        m.move(-1, 0, 0)
    if cpx.touch_A3:
        m.move(1, 0, 0)
    if cpx.touch_A7:
        m.move(0, -1, 0)
    if cpx.touch_A1:
        m.move(0, 1, 0)
コード例 #27
0
    # use D3 as capacitive touch to turn on internal LED,
    # and enable or disable the move feature.
    led.value = touch.value
    if touch.value:
        moveEnabled = not moveEnabled
        time.sleep(0.2)  # a shitty debounce
        if moveEnabled:
            # re-init our shake variable state,
            # but go ahead and have the next move be now.
            nextMouseShake = frameTime
            shakeRemaining = 0

    if moveEnabled:
        # if we are currently shaking, update our shake
        if (shakeRemaining > 0):
            shakeRemaining -= delta
            movePercent = math.sin(shakeRemaining * 3.14159)
            moveAbsolute = int(shakePixelsHalf * movePercent)
            moveDelta = moveAbsolute - mousePos
            #print("Shake move: {}, {}, {}".format(moveDelta, moveAbsolute, mousePos))
            mouse.move(moveDelta, 0)
            mousePos += moveDelta
        # if not shaking, check if it's time to shake the mouse
        elif (frameTime >= nextMouseShake):
            shakeRemaining = moveMouseShakeTimeSeconds
            nextMouseShake = frameTime + moveMouseShakeTimeSeconds + moveMouseEverySeconds
            mousePos = 0

    time.sleep(0.01)  # make bigger to slow down
    lastFrameTime = frameTime
コード例 #28
0
        #  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))
            print("y", steps(y))
            clock = time.monotonic()

    ble.start_advertising(advertisement)
コード例 #29
0
button5.direction = digitalio.Direction.INPUT
button5.pull = digitalio.Pull.UP
button5_state = None

encoder = rotaryio.IncrementalEncoder(board.D11, board.D5)
last_position = encoder.position

print("Waiting for button presses")

while True:
    # rotary reference for CP here: https://learn.adafruit.com/rotary-encoder/circuitpython
    current_position = encoder.position
    position_change = current_position - last_position
    if position_change > 0:
        for _ in range(position_change):
            m.move(0, 0, 1)
        print(current_position)
    elif position_change < 0:
        for _ in range(-position_change):
            m.move(0, 0, -1)
        print(current_position)
    last_position = current_position
    # Refresh (F5)
    if button5.value and button5_state is None:
        button5_state = "pressed"
    if not button5.value and button5_state == "pressed":
        print("Refresh #5 button pressed.")
        kbd.send(Keycode.F5)
        button5_state = None

    #Twitter
コード例 #30
0
while True:

    accel = nc.acceleration
    #    print(accel)
    #    x, y = nc.joystick
    #    print((x,y))
    x = accel[0] / 4
    y = accel[1] / 4
    print((x, y))
    # Eliminate spurious reads
    if x == 255 or y == 255:
        continue
    relX = x - centerX
    relY = y - centerY

    m.move(int(scaleX * relX), int(scaleY * relY), 0)
    buttons = nc.buttons

    c = buttons.C
    z = buttons.Z

    if z and not zDown:
        stillDown = True
        for n in range(CHECK_COUNT):
            if nc.button_Z:
                stillDown = False
                break
        if stillDown:
            m.press(Mouse.LEFT_BUTTON)
            zDown = True
    elif not z and zDown:
コード例 #31
0
ファイル: scroll.py プロジェクト: eiselekd/hw
import time
import board
import digitalio
from adafruit_hid.mouse import Mouse

mouse = Mouse()

# define buttons. these can be any physical switches/buttons, but the values
# here work out-of-the-box with a CircuitPlayground Express' A and B buttons.
up = digitalio.DigitalInOut(board.D4)
up.direction = digitalio.Direction.INPUT
up.pull = digitalio.Pull.DOWN

down = digitalio.DigitalInOut(board.D5)
down.direction = digitalio.Direction.INPUT
down.pull = digitalio.Pull.DOWN

while True:
    # scroll up one unit (varies with host/OS)
    if up.value:
        mouse.move(wheel=1)

    # scroll down one unit (varies with host/OS)
    elif down.value:
        mouse.move(wheel=-1)

    time.sleep(0.1)