Forums

I made a way to send ^C on iPadOS

The iPadOS update includes desktop-class browsing, and this makes PythonAnywhere consoles work better on iPad. You can now use a physical keyboard to input keys like alt and ctrl instead of using the row of keys on the bottom. This also fixes the issue where consoles aren't big enough on iPads with a large display.

But there is a problem caused by the update: you can't do ctrl+c in consoles. So I have successfully made a Shortcut that solves this problem:

screen recording

I plan to also add other keys like esc and the function keys, then I'll post the iCloud link to the shortcut so you can use it

I need some help here. I have been able to successfully send a keyboard interrupt by sending a POST request to /api/v0/user/{username}/consoles/{id}/send_input/ and setting the input field to \003. But what do I put in the input field if I want to input Esc or a function key?

I believe the escape key would be chr(27) or \x1b in a string literal. I don't think the function keys have a representation that can work in strings, but I'd be happy to be proved wrong on that.

Doesn't work. I'm doing this in the Shortcuts app by running Javascript in the webpage to figure out what character(s) to send to the API, then use the "Get Contents of URL" action in Shortcuts to send the request. Maybe I can instead try sending the request through JavaScript (running on the console page)

Nevermind, I actually got the Esc key to work. I forgot about this line in the JavaScript code that I added for testing purposes which broke it

I also got Ctrl+V to work.

I have spent like an hour last night looking through the xterm specification to figure out a way to send function keys, but to no avail. I'm gonna remove those useless function keys from my shortcut and post the link

Version 1

Here's the link: https://www.icloud.com/shortcuts/b7426a0338964c4d8be3da3e0a50d92c

In order for the shortcut to work, you have to manually create another shortcut called "Get PythonAnywhere API Token" that takes a PythonAnywhere username as input and outputs the API token for that user. It's done this way so that it works for people with multiple accounts. Here is an example:

example

If you only have one account, you can instead just put a "Text" action in the shortcut that has the token

That's really awesome, @dull! Thanks for posting it :-)

I have now figured out how to make function keys work, thanks to this. I'm gonna release version 2 of the shortcut after I implement all of the keys. I have tested F1 so far and it works.

Cool, so how it's done is a list of iOS browser shortcuts that take say ^C from your browser and uses the PythonAnywhere api to do a ^C in the PythonAnywhere console? And you need the token shortcut to have a pluggable/reusable shortcut so you don't need to add in the token again for every shortcut?

Shortcuts is an iOS feature which is basically a drag-and-drop scripting language. This shortcut is activated through the share sheet of a webpage, and it uses regex to get the console id and username from the URL. It then shows a menu to select a key to send, then it sends the API request

Shortcuts is very useful if your shortcuts need to be integrated with features or apps in iOS such as Safari or device settings

Version 2 of the shortcut will run much faster now because it now runs itself using the "Run Shortcut" action with the "Show While Running" option disabled. Normally, Shortcuts steps through the shortcut's actions and causes a short delay for each action, but disabling the Show While Running option prevents this from happening. This solution is inspired by this shortcut

Version 2

https://www.icloud.com/shortcuts/c4e97b73a48246a9acc6cf26cff31d2f

This adds support for function keys (most of them don't seem to work properly) and runs faster