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

onKeyPressed doesn't listen for modified (e.g. ctrl-u, alt-a, etc.) characters #104

Open
stephentalley opened this issue Dec 17, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@stephentalley
Copy link

Our app has a need to listen to various control-modified keys (ctrl-u, ctrl-f, ctrl-b, etc.). But:

session {
    var keyPressed by liveVarOf<Key?>(null)
    section {
        if (keyPressed != null) {
            textLine("key pressed: $keyPressed")
        }
    }.runUntilKeyPressed(Keys.Q, Keys.ESC) {
        onKeyPressed {
            keyPressed = key
        }
    }
}

…shows those keys are ignored.

Is there an API to listen for those keys?

  • OS: Linux
  • Version 1.1.1
@stephentalley stephentalley added the bug Something isn't working label Dec 17, 2023
@bitspittle
Copy link
Contributor

I don't have access to anything except that which the terminal gives me. So depending on what you're expecting, it's probably not possible. See also: #57 in case it's related.

I wonder if you could write a raw console app, just like a naked main function and use of readLine, and see if you're getting characters in that case.

@bitspittle
Copy link
Contributor

bitspittle commented Dec 24, 2024

A user on my Discord just pointed out that Mordant has rich support for raw keypresses. Taking notes here.

Mordant actually supports three implementations that apparently supply raw mode logic.

Between these three, I think JNA is the way to go. However, I'll need to investigate to see by how much the native library increases the jar size. If it's like a few MBs or less, it may be worth it just to do it. Putting the logic in a separate module doesn't seem too bad.

JNA implementation for windows

Still not sure how mac and linux work. Will investigate later.


If I can get this working right, I think for a first pass, I would mostly keep onKeyPressed the same, except I would add
ctrl, alt, and shift booleans. I might also see if I can generate key presses for just CTRL, ALT, and SHIFT on their own.


TODO:

  • Figure out bundle size of native library / libraries for JNA solution
  • Figure out how linux works
  • Figure out how mac works
  • Update Kotter

@bitspittle bitspittle self-assigned this Dec 24, 2024
@KyleMcB
Copy link

KyleMcB commented Dec 25, 2024

I am using kotter to make a shell and also needed alt+n ctrl+n
I wrote my own system to collect and interpret from Terminal.read() from kotter
I'll share it here, but its super early. I wouldn't be surprised if it only works on iTerm2. probably won't work with xterm. also you have to use a runUntilSignal and collect the in the runscope.
https://github.com/KyleMcB/kross/blob/develop/kross/src/main/kotlin/com/xingpeds/kross/utf8Input.kt
my code isn't documented or tested yet sorry. Also it doesn't detect alt+ctrl+n you probably could. I hit a complexity limit before I document and refactor. See the app entry point at
https://github.com/KyleMcB/kross/blob/develop/kross/src/main/kotlin/com/xingpeds/kross/App.kt
note how I signal() and cancel the collectionScope when someone pressing enter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants