Thanks so much Robert!
I am using your mpr code and it works great!
I didn't know anything about the sledge hammer to capture `Ctrl-C` properly.
Is it for Windows only or does it apply to linux as well?
I have just tweaked it a bit to replace `Ctrl-]` by `Ctrl-X` (b"\x18") to exit the Repl properly as for any reason the key combination `Ctrl-^` doesn't do the job with my keyboard anymore.
But I think I understand the mpr code enough to modify it to show me some ASCII codes when I type `Ctrl-Key` commands. With this, I'll be able to check again every combination and eventually find the standard way to exit the Repl with my keyboard.
rshell cp command not working on Raspberry Pi Pico with MicroPython installed
Re: rshell cp command not working on Raspberry Pi Pico with MicroPython installed
The Ctrl-C catch works on Linux and the board's micropython too. But both on Linux and the boards there is a better way to disable Ctrl-C interrupt. Maybe on Windows too, but I was not in the mood to search deeply.
About key codes: I made a small python script for windows to find the keys. It is just a few lines:
Funny enough, this one does not raise an KeyboardInterrupt Exception on Ctrl-C. So the exception may be caused in the part of the code outside the getch() call.
If you are using pye: Ctrl-X is used for the "Cut" action (the common Ctrl-C, Ctrl-X, Ctrl-V for cut & paste). But with pye you can also use the two keypresses "Esc char" sequence instead of Ctr-char. On Linux, Alt-Char creates the Esc + char sequence
In the Windows console it may be necessary to disable the "use ctrol keys" setting of the window.
About key codes: I made a small python script for windows to find the keys. It is just a few lines:
Code: Select all
from msvcrt import getwch
c = ""
while c != "\x03":
c = getwch()
print("%02x" % ord(c))
If you are using pye: Ctrl-X is used for the "Cut" action (the common Ctrl-C, Ctrl-X, Ctrl-V for cut & paste). But with pye you can also use the two keypresses "Esc char" sequence instead of Ctr-char. On Linux, Alt-Char creates the Esc + char sequence
In the Windows console it may be necessary to disable the "use ctrol keys" setting of the window.
Re: rshell cp command not working on Raspberry Pi Pico with MicroPython installed
I did use your little piece of code to track the ASCII values obtained when pressing keys and key combinations. It works great.
Strangely there is no output at all when pressing on `Ctrl-^`, or all other `Ctrl-Keys` around (`Ctrl-$`, `Ctrl-ù`, etc.).
I recall `Ctrl-^` working a few days ago thought. I cannot explain what changed in the meantime.
I also played a bit with Microsoft Keyboard Layout Creator (MSKLC) Version 1.4 and defined a new keyboard layout where `Ctrl-)` (as `)` and `]` are on the same key) sends the 0x001d value. This new keyboard definition works fine and exits the Repl properly in a standard cmd window. However when using the terminal window in Microsoft Code, `Ctrl-)` doesn't work anymore, and the only way I found to exit the Repl is to disconnect the Raspberry Pico, throwing an error. Microsoft Code might be capturing and redirecting Ctrl commands, I don't know.
Indeed `Ctrl-X`is definitely not the best shortcut to exit mpr as it might deprive pye from that shortcut. Any idea of a `Ctrl-Letter` combination that is not often used and thus could be chosen to exit mpr?
Strangely there is no output at all when pressing on `Ctrl-^`, or all other `Ctrl-Keys` around (`Ctrl-$`, `Ctrl-ù`, etc.).
I recall `Ctrl-^` working a few days ago thought. I cannot explain what changed in the meantime.
I also played a bit with Microsoft Keyboard Layout Creator (MSKLC) Version 1.4 and defined a new keyboard layout where `Ctrl-)` (as `)` and `]` are on the same key) sends the 0x001d value. This new keyboard definition works fine and exits the Repl properly in a standard cmd window. However when using the terminal window in Microsoft Code, `Ctrl-)` doesn't work anymore, and the only way I found to exit the Repl is to disconnect the Raspberry Pico, throwing an error. Microsoft Code might be capturing and redirecting Ctrl commands, I don't know.
Indeed `Ctrl-X`is definitely not the best shortcut to exit mpr as it might deprive pye from that shortcut. Any idea of a `Ctrl-Letter` combination that is not often used and thus could be chosen to exit mpr?
Re: rshell cp command not working on Raspberry Pi Pico with MicroPython installed
No, I do not know any better single code. You may eventually use a control code which is more rarely used, like Ctrl-T (in pye: go to line 1). Or you go for a function key. For that, you have to move the exit call into the branch after
while ch in b"\x00\xe0": # arrow or function key prefix?
I modified my little script to show function and cursor keys better:
while ch in b"\x00\xe0": # arrow or function key prefix?
I modified my little script to show function and cursor keys better:
Code: Select all
from msvcrt import getwch
c = ""
while c != "\x03":
c = getwch()
if c in '\x00\xe0':
print("%02x %02x" % (ord(c), ord(getwch())))
else:
print("%02x" % ord(c))
Re: rshell cp command not working on Raspberry Pi Pico with MicroPython installed
I might do that indeed! Your first or the second option.
I have just tried it. I didn't note some radical differences with the previous script.
What is weird to me is that Ctrl-` switches focus in Microsoft Code between the file editor and the terminal. It works just fine using my keyboard. But in your script (and mpr I believe so) it doesn't bring out any display code. It is like if the key combination is not even pressed.
Re: rshell cp command not working on Raspberry Pi Pico with MicroPython installed
The difference is when you push a function or cursor key, which issues two bytes. These are then displayed in a single line. Indeed not a huge difference.I didn't note some radical differences with the previous script.
Re: rshell cp command not working on Raspberry Pi Pico with MicroPython installed
Indeed that I noticed and figured out by reading your code. Works great! Especially with arrow keys!
What I will do is define a new keyboard layout in MSKLC where `Ctrl-^` sends 0x00d1 (as `Ctrl-]` is supposed to do) and test it out in Microsoft Code.
Re: rshell cp command not working on Raspberry Pi Pico with MicroPython installed
VSCode doesn't seem to block/redirect the `Ctrl-^` key stroke as it works great now exiting mpr with my new keyboard layout definition.
Additionally,`Ctrl-]` (`Ctrl-)`) works too in a standard Windows console.
Thanks Robert for making me domesticate mpr, a great tool! You should push your improvements to it in its dedicated repo!
Additionally,`Ctrl-]` (`Ctrl-)`) works too in a standard Windows console.
Thanks Robert for making me domesticate mpr, a great tool! You should push your improvements to it in its dedicated repo!