rshell cp command not working on Raspberry Pi Pico with MicroPython installed

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
User avatar
sebi
Posts: 48
Joined: Tue Mar 29, 2016 9:36 pm
Location: France

Re: rshell cp command not working on Raspberry Pi Pico with MicroPython installed

Post by sebi » Mon Feb 08, 2021 10:03 am

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.

User avatar
Roberthh
Posts: 2462
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: rshell cp command not working on Raspberry Pi Pico with MicroPython installed

Post by Roberthh » Mon Feb 08, 2021 10:13 am

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:

Code: Select all

from msvcrt import getwch

c = ""
while c != "\x03":
    c = getwch()
    print("%02x" % ord(c))
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.

User avatar
sebi
Posts: 48
Joined: Tue Mar 29, 2016 9:36 pm
Location: France

Re: rshell cp command not working on Raspberry Pi Pico with MicroPython installed

Post by sebi » Mon Feb 08, 2021 3:52 pm

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?

User avatar
Roberthh
Posts: 2462
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: rshell cp command not working on Raspberry Pi Pico with MicroPython installed

Post by Roberthh » Mon Feb 08, 2021 4:22 pm

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:

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))

User avatar
sebi
Posts: 48
Joined: Tue Mar 29, 2016 9:36 pm
Location: France

Re: rshell cp command not working on Raspberry Pi Pico with MicroPython installed

Post by sebi » Mon Feb 08, 2021 4:51 pm

Roberthh wrote:
Mon Feb 08, 2021 4:22 pm
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.
I might do that indeed! Your first or the second option.
Roberthh wrote:
Mon Feb 08, 2021 4:22 pm
I modified my little script to show function and cursor keys better.
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.

User avatar
Roberthh
Posts: 2462
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: rshell cp command not working on Raspberry Pi Pico with MicroPython installed

Post by Roberthh » Mon Feb 08, 2021 5:05 pm

I didn't note some radical differences with the previous script.
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.

User avatar
sebi
Posts: 48
Joined: Tue Mar 29, 2016 9:36 pm
Location: France

Re: rshell cp command not working on Raspberry Pi Pico with MicroPython installed

Post by sebi » Mon Feb 08, 2021 5:14 pm

Roberthh wrote:
Mon Feb 08, 2021 5:05 pm
The difference is when you push a function or cursor key, which issues two bytes. These are then displayed in a single line.
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.

User avatar
sebi
Posts: 48
Joined: Tue Mar 29, 2016 9:36 pm
Location: France

Re: rshell cp command not working on Raspberry Pi Pico with MicroPython installed

Post by sebi » Mon Feb 08, 2021 5:40 pm

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!

Post Reply