11

AFAIK emacs does not support keyup/keydown events, only keypressed. An example of a consequence is that when we want to mark a region we have to first set a mark set-mark-command and can then mark the region by moving around the point. While this is really an interesting feature as you don't have to hold a shift key pressed while marking the text, sometimes it would be desirable to have the same behavior like in other editors. This question is to understand why emacs doesn't support this feature and why this is considered better. Also is there an ideomatic approach how we could solve this in emacs?

Dan
  • 32,584
  • 6
  • 98
  • 168
shaft
  • 213
  • 1
  • 4
  • 6
    Emacs also works in a terminal, and key up/down events don't make sense in that environment. Quite likely, that is at least a *historical* reason why these events aren't supported. That doesn't mean they *couldn't* be supported though. I suspect nobody has seen a sufficiently pressing need to bother with it. – Harald Hanche-Olsen Apr 02 '15 at 08:43
  • 1
    Okay that's a valid argument, though there are other features in emacs that only work in a graphical environment (fonts, mouse events, etc) – shaft Apr 02 '15 at 08:55
  • Yes, but those are much more necessary in a graphical environment. Mouse up/down events fall more into a “nice to have” category. – Harald Hanche-Olsen Apr 02 '15 at 10:24
  • 3
    I wrote some code that simulates key up/down events to preview a file on key down then close the preview buffer on key up, like the answer says it's hacky, but maybe it could be molded into something stable. https://emacs.stackexchange.com/questions/275/dired-quick-view-key-to-preview-the-file-at-point/296#296 – Jordon Biondo Apr 02 '15 at 13:12
  • 3
    What "same behavior like in other editors" are you referring to [I don't use those other text editors]? The rest of the text seems to hint at "shift+movement to select", but that is already supported in Emacs. – Stefan Apr 02 '15 at 14:10
  • Incidentally, emacs does support up/down events for the mouse. – T. Verron Apr 02 '15 at 14:26
  • @HaraldHanche-Olsen I'm pretty sure that's an answer. – Malabarba Apr 02 '15 at 16:20
  • 5
    Though you're right these key events don't exist in Emacs, you should know that Emacs *does* support shift selection (if that's what inspired your question). – Malabarba Apr 02 '15 at 16:23

1 Answers1

2

As answered in comments for historical reason Emacs run in terminals and those devices are character oriented - you get byte sequence without any guarantee when this happen at keyboard.

Discussion also point that it is possible to implement this for graphical environment. But nobody interested in that.

Note that some programs like games or music software may use detailed info about when key pressed, how long, and when released but text editing have nothing common with these.

From manual (info "(elisp)Mouse Events"):

Emacs supports four kinds of mouse events:
click events, drag events, button-down events, and motion events.

Hover event can be emulated by idle timer - analyzing thing at point after delay.

gavenkoa
  • 3,352
  • 19
  • 36
  • “… but text editing have nothing common with these.”—Emitting text on key-up events can be useful when implementing key chords (in the stenography-sense). That way you don’t have to rely on timeouts when implementing key chords. Just look at [all the hoops](https://www.emacswiki.org/emacs/KeyChord) that `key-chord` users have to jump through; anaylzing bigram frequencies, “I adjusted key-chord to sample my current typing frequency”, and so on. – Guildenstern Sep 08 '20 at 16:30