Skip to content
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

Python/ion: keydown(KEY_BACK) not usable #2282

Open
XanderLeaDaren opened this issue Jan 9, 2025 · 2 comments
Open

Python/ion: keydown(KEY_BACK) not usable #2282

XanderLeaDaren opened this issue Jan 9, 2025 · 2 comments

Comments

@XanderLeaDaren
Copy link
Contributor

Describe the bug

Any Python script is halted by the [ ↰ ] key next to [OK], so it’s impossible to test keydown(KEY_BACK) in a program.

To Reproduce

Steps to reproduce the behavior:

  1. Write a minimalist Python script like the one below:
    from ion import *
    print("BACK not pressed yet")
    while True:
    if keydown(KEY_BACK):
    print("BACK key pressed")
  2. Execute the script
  3. Press the [ ↰ ] key
  4. The script halts, with the message: KeyboardInterrupt:

Expected behavior

If a Python script involves a test with the BACK key, it should not be halted by this key — the ON key is a “solution” to halt the program anyway.

Environment

  • Online simulator (version 23.2.1)
  • Actual device (version 24.0.1)
@XanderLeaDaren
Copy link
Contributor Author

Maybe related: #1316[Python] Back doesn't have any effect in while True loop.

@Yaya-Cout
Copy link

It's possible to disable or rebind the back key to use it in scripts, using

import micropython as mp
mp.kbd_intr(-1) # Disable KeyboardInterrupt

Or, alternatively:

from ion import *
import micropython as mp
mp.kbd_intr(KEY_OK) # Bind the OK key to KeyboardInterrupt instead of the Back key

It's used by some games. I don't know if it's an intended feature, but it's really useful for such use. I don't think disabling the behavior would be useful as it's possible to exit everything using Home/Power since version 16 (which broke games as playing using the top keys is way easier than with the small keys).
On version 15 and before, this feature must be used with caution as it's impossible to exit the script without explicit exit from the script itself (it's not a concern for NumWorks as they probably only care for the new versions, but if you are deploying your script on a lot of calculators, some people use outdated software as they never update, or are running custom firmwares based on version 15).

Automatically disabling the back key could be a solution, for instance once keydown(KEY_BACK) is called once, the KeyboardInterrupt would be disabled for the rest of the execution of the script.

It would be interesting to know the official position for NumWorks for this use case (I'm not affiliated to NumWorks in any way, I'm just one of the contributors on a custom firmware on old NumWorks calculators and maintain some external apps).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants