0% found this document useful (0 votes)
6 views2 pages

Python Serial Control Script

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Python Serial Control Script

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

# pc_control.

py

import serial

import sys

import time

from pynput import keyboard

ser = [Link]('COM3', 9600, timeout=0.1) # change COM port

def send(ch):

[Link]([Link]())

print("sent:", ch)

def on_press(key):

try:

if key == [Link]:

send('F')

elif key == [Link]:

send('B')

elif key == [Link]:

send('L')

elif key == [Link]:

send('R')

elif hasattr(key, 'char'):

ch = [Link]()

if ch == 'u':

send('U')

elif ch == 'd':

send('D')
elif ch == 'o':

send('O')

elif ch == 'c':

send('C')

elif ch == 's':

send('S')

except Exception as e:

print("err", e)

with [Link](on_press=on_press) as listener:

[Link]()

You might also like