question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support comparators for matching keyboard input to meta and ctrl keys

See original GitHub issue

Problem

Ctrl keys, such as ^C are not considered sequences and must be matched by their raw escape codes. We propose a change:

- if term.inkey() == '\x03':
+ if term.inkey() == term.KEY_control('c')

Furthermore, the legacy (and not recommended for modern applications, IMO) to support alt or meta by escape,

        # TODO(jquast): "meta sends escape", where alt+1 would send '\x1b1',
        #               what do we do with that? Surely, something useful.
        #               comparator to term.KEY_meta('x') ?
        # TODO(jquast): Ctrl characters, KEY_CTRL_[A-Z], and the rest;
        #               KEY_CTRL_\, KEY_CTRL_{, etc. are not legitimate
        #               attributes. comparator to term.KEY_ctrl('z') ?

as well as https://github.com/erikrose/blessings/pull/27#issuecomment-18450260 and https://github.com/erikrose/blessings/pull/44

Note: this backported from upstream https://github.com/erikrose/blessings/issues/98

How would we support the advanced ctrl, shift, and alt combinators of #73 ?

First Proposal

New methods KEY_control(ucs) and KEY_meta(ucs), returning a Sequence instance(?), \x03 for Ctrl-C and \x1b[c for Alt-C, that can be compared for equality for a given sequence (by their equivalent raw string value). As Unicode-derived class Sequence, this should work without supporting stub code for both left and right-hand side operations. The code value should remain its numeric ascii value for control. For meta characters, code should be value None.

Second Proposal

Further decorate the Keystroke class to provide new methods:

control (or ctrl or both) alt (or meta or both) shift (may not support… difficult)

Which accepts an optional 1-unicode-character input in range of ascii (a-zA-Z, punctuations, etc.).

So that, with ctrl-c, the unicode string is u'\x03' and its method .ctrl() returns True, .ctrl('c') returns True, and .ctrl(‘z’) returns False.

Similarly, with alt+x, the unicode string is u'\x1bx' and its method .alt() returns True, .alt('x') returns True, and .alt('p') returns False.

Third Proposal

Support .is_compound_format_testing() tester, somewhat like blessings project, example:

if term.inkey().is_alt_shift('z'):
    # fancy way of saying alt+Z was pressed.
if term.inkey().is_ctrl_shift('c'):
    # may never test true, dragons be here
inp = term.inkey()

This would for example support testing key combinations such as

#define SHIFT_ALT_CTRL_PF7_KEY           "\033[18;8~" 

shift is difficult. In ‘\x03’ (^C), we would test that shift is not pressed. But it could just as easily be pressed, and we wouldn’t know. We would chose false unless it tested against upper().

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
thomasballingercommented, Dec 3, 2015

I most like the first proposal because it seems most straightforward.

I could imagine pining for things like SHIFT_ALT_CTRL_PF7_KEY in the future, but have no interest in them now. It seems like these could be added to term as well in the future?

0reactions
jquastcommented, Oct 17, 2022

Related, #222

Read more comments on GitHub >

github_iconTop Results From Across the Web

Key values for keyboard events - Web APIs - MDN Web Docs
The tables below list the standard values for the KeyboardEvent.key property, with an explanation of what the key is typically used for.
Read more >
Keyboard Events and Handlers | Alexa Skills Kit
Alexa Presentation Language (APL) provides support for keyboard events and handlers. About keyboard support. KeyUp and KeyDown keyboard events are generated ...
Read more >
Clink v1.4.4 - GitHub Pages
Tab and Ctrl - Space will do match completion two different ways. Press Alt - H to see a list of the current...
Read more >
Search | Stripe Documentation
Look up objects in your Stripe data. Overview. Some top level API resources support retrieval with search API methods. You can use the...
Read more >
Keyboard Input Overview - Win32 apps - Microsoft Learn
Key location 101/102 Enhanced keyboard Scan 1 make Scan 1 break DO NOT USE 00 80 DO NOT USE E0_00 E0_80 1 ~ ` 29 A9...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found