#๐Ÿ”’ Curses library, Ctrl + (Key) detection

11 messages ยท Page 1 of 1 (latest)

old pond
#

Hi! I'm using curses to make a text editor-like program.
I'm using the getkey() function to read user input.
I want to program special features for key combinations, for example CTRL + Z to undo changes, but when I press that key combination and print its value, it gets ^Z , and something like if key == "^Z" does not work properly, and always just returns False.
With combinations like CTRL + ENTER, it gets CTL_ENTER and works just fine in if statements, unlike CTRL + (Any letter).
I can't find anything in the documentation and I'm not sure how to proceed.

cold plumeBOT
#

@old pond

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

old pond
#

Yup figured it out.

#

For anyone in the future:

#

do whatever = ord(key), with key as your input value, and then print it to the screen, and just use the ascii value of ^Z and manually type it in!

#

Once you have the int ascii value of your weird character, do

#

if key == chr(whatever)

#

and it will just work ๐Ÿ‘

cold plumeBOT
#

@old pond

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

๐Ÿ”’ Curses library, Ctrl + (Key) detection