Page 1 of 1

Pi Pico Keyboard Emulator HELP?

PostPosted: Tue Mar 16, 2021 1:08 am
by xbizob
Tried to store the keys_pressed data in a file on the pico... info.txt as follows...

Keycode.A
"Hello, World!"
"https://cytro-pi-pico"

..................................

I added the following code to read the info.txt file...

keys_pressed = []
with open("/info.txt", "r") as file:
print("Reading file from PICO")
for line in file:
keys_pressed.append(line.strip())


the result is ...

['Keycode.A', '"Hello, World!"', '"https://cytron.io/p-maker-pi-pico\n"]

not like whats hard coded into the program...

[Keycode.A, "Hello, World!", "https://cytron.io/p-maker-pi-pico\n"]

tried taking out the single quotes, and other options, but cant find a way to make it work???

PLEASE HELP!!!

Thank you... Robert

Re: Pi Pico Keyboard Emulator HELP?

PostPosted: Tue Mar 16, 2021 9:33 pm
by Idris
Hi Robert,

You can use filter() function in python to filter certain character. For example.

python filter.png

Reference: Python : filter() function | Tutorial & Examples

Re: Pi Pico Keyboard Emulator HELP?

PostPosted: Thu Mar 18, 2021 9:38 am
by xbizob
#Rasberry Pi PICO ... Circuitpython

import time
import board
import digitalio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode

keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS(keyboard) # We're in the US :)

# If I run the code ...............
key = Keycode.A
print(type(key))
print(key)
keyboard.press(key)

# ...........I get ... <class 'int'> and 4 ... types a lower case a

#......................................................................

# If I store Keycode.A in line one of a file info.txt

with open("/info.txt", "r") as file:
for line in file:
key=line
print(type(key))
print(key)
keyboard.press(key)

# ...........I get ... <class 'str'> and Keycode.A and get type error
#File "/lib/adafruit_hid/keyboard.py", line 81, in press
#File "/lib/adafruit_hid/keyboard.py", line 116, in _add_keycode_to_report
#File "/lib/adafruit_hid/keycode.py", line 295, in modifier_bit
#TypeError: unsupported types for __le__: 'int', 'str'


# how do I convert this key string data intol the same imput as me defining ... key = Keycode.A


# I have tried stripping the quotes, and converting it to a int... I have tried converting it to a a list, and using split() format etc...

# please help... driving me crazy!!!!

Re: Pi Pico Keyboard Emulator HELP?

PostPosted: Tue Mar 23, 2021 11:03 am
by Idris
Hi xbizob,

Could you share a complete code? So that I can test it on my Pico. :)