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

Unable to capture some modified key strokes. #32

Closed
AndrewRademacher opened this issue Dec 26, 2015 · 4 comments
Closed

Unable to capture some modified key strokes. #32

AndrewRademacher opened this issue Dec 26, 2015 · 4 comments

Comments

@AndrewRademacher
Copy link
Contributor

I have a small demo using the following event loop

event :: State -> Event -> EventM (Next State)
event st e = do
    liftIO $ print e
    continue st

and the following draw function

draw :: State -> [Widget]
draw st = [str "Hello World!"]

There are several cases like Ctrl+,, Ctrl+., and Ctrl+/ that do not fire an event. Additionally there is at least one case of sending the wrong event. For example you would expect Ctrl+m to read...

EvKey (KChar 'm') [MCtrl]

however it actually reads...

EvKey KEnter []
@jtdaugherty
Copy link
Owner

Unfortunately this behavior depends almost entirely on your terminal emulator of choice and the active termcap settings; to see what I mean you might consider trying different terminal emulators and different modifier key combinations.

In the particular case of C-m and Enter, the value for C-m is equivalent to Enter so there isn't a way to distinguish. This is also true of Tab and C-i. So from that perspective, seeing KEnter when C-m is pressed is expected behavior.

As examples of this kind of behavior, these pages might be illuminating:

http://askubuntu.com/questions/441744/pressing-enter-produces-m-instead-of-a-newline
http://stackoverflow.com/questions/598113/can-terminals-detect-shift-enter-or-control-enter

Sadly, terminal application programmers typically need to select control-key combinations that are likely to work on a wide variety of terminal emulators to avoid this problem.

@AndrewRademacher
Copy link
Contributor Author

Sad indeed. Thanks for the heads up.

@hramrach
Copy link

Thanks for looking into this.

Regarding the key mapping - aren't key mappings in some database so applications know what to expect on which terminal?

If not how is anything ever supposed to work on a terminal?

Or is that why vi uses key sequences rather than modifiers most of the time?

Because the modifiers break?

@jtdaugherty
Copy link
Owner

@hramrach - yes, termcap is the database you mentioned. Still, that is not necessarily enough to make this work for all emulators and all modifier key combinations. It might be something that @coreyoconnor could address by making changes to vty (which brick uses to handle keyboard input events), though.

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

3 participants