Pi Pico Keyboard Emulator HELP?

Please feedback the issue encountered while using Cytron official website (http://www.cytron.com.my), Cytron Technical Forum and Cytron Tutorial site (http://tutorial.cytron.com.my) here. We greatly appreciate any comments and suggestions too.

Pi Pico Keyboard Emulator HELP?

Postby xbizob » Tue Mar 16, 2021 1:08 am

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
xbizob
Greenhorn
 
Posts: 2
Joined: Tue Mar 16, 2021 12:33 am

Re: Pi Pico Keyboard Emulator HELP?

Postby Idris » Tue Mar 16, 2021 9:33 pm

Hi Robert,

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

python filter.png

Reference: Python : filter() function | Tutorial & Examples
Cytron Technologies invest time and resources providing tutorial, training and support for STEM education and maker movement. We need your support by purchasing products from Cytron Technologies. Thanks.
http://www.cytron.com.my
User avatar
Idris
Moderator
 
Posts: 409
Joined: Thu Mar 22, 2012 5:28 pm
Location: Pulau Pinang

Re: Pi Pico Keyboard Emulator HELP?

Postby xbizob » Thu Mar 18, 2021 9:38 am

#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!!!!
xbizob
Greenhorn
 
Posts: 2
Joined: Tue Mar 16, 2021 12:33 am

Re: Pi Pico Keyboard Emulator HELP?

Postby Idris » Tue Mar 23, 2021 11:03 am

Hi xbizob,

Could you share a complete code? So that I can test it on my Pico. :)
Cytron Technologies invest time and resources providing tutorial, training and support for STEM education and maker movement. We need your support by purchasing products from Cytron Technologies. Thanks.
http://www.cytron.com.my
User avatar
Idris
Moderator
 
Posts: 409
Joined: Thu Mar 22, 2012 5:28 pm
Location: Pulau Pinang


Return to Cytron Website, Forum & Tutorial Site Feedback

Who is online

Users browsing this forum: No registered users and 4 guests

cron