-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Writing a string does not work with a single button press #8
Comments
Hi @Charlie22911 ! First, I wonder if you're using any of the example code from this repo? It sounds like maybe you're using the "SixKeys-Template" code? Did you modify the main.py file? If you made any changes, could you paste it into a comment here so that I can have a closer look at what might be going on? The error is pointing to line 28 in the If you changed this line, or if you added more than just a keycode in the Andy |
Apologies for the delay, I was preoccupied with the wonderful kit from Tindie. The specific change that breaks things is changing line 19 to: Here is main.py as it sits on my trinket now:
I've made other superficial changes to help get a grasp at whats going on, but I don't think they are responsible. miniKbdButtons.py is unchanged. |
I got things working, but not in the way I expected. I cobbled together bits of arduino code from various sources online. I think I'd rather figure out how to make it work in circuit python since I haven't accomplished my goal by such "cheating". Here is the relevant code, I'm sure its a horror show (not that I'd know):
|
HI @Charlie22911 , Thanks for posting your code, let me walk you through what's happening. From your Python traceback, the error can be found on line 28 in your main.py:
The For this to work, all of the values in the dictionary should only be single keycodes. But I see on line 19 you changed the entry for ID 1 to If you want to assign actions to the keys as a dictionary of strings instead of a dictionary of keycodes, then let me point you in the right direction. First, change all of the values in the
...and then change the callback on line 28 to write the string that it fetches from the dictionary instead of pressing a single key. This is where you'll use the
This is untested but it should work, I hope it makes sense what's going on. But if not let me know and I can go into a little bit more depth! |
Thank you for the quick reply, making the suggested changed results in the the string typing out correctly, but it crashes immediately after the string completes:
Could this have something to do with the function that releases the keys after being pressed, being that a string is not a key? main.py below:
|
Ah yes! I knew I should have tested my reply before sending it but I didn't have a MiniKbd on hand at the moment. In CircuitPython, the keyboard can work in two ways — you can press and hold keys and then release them, or you can have it write a string to type it out character by character. Since you've switched to writing strings, you can remove line 32, the line with the Adafruit's demo code for the HID Keyboard module has an interesting solution where it uses a condition between lines 57 and 61 where it chooses to |
Working on my first project involving any degree of code, and also my first github post; I'm looking to use this as way to insert strings with a single button press (for example, game server commands).
Using "kbdLayout.write('This is a test!')" for example causes it to insert that string when the trinket boots, and subsequently locks up on the next button press.
Using Mu serial monitor I see:
I'm not really sure how to approach this, any help would be appreciated.
The text was updated successfully, but these errors were encountered: