mabe02 / lanterna

Java library for creating text-based GUIs
GNU Lesser General Public License v3.0
2.23k stars 243 forks source link

Detect cmd key modifier on MacOS #526

Closed rockwotj closed 3 years ago

rockwotj commented 3 years ago

It seems that the keystoke implementation can detect ctrl, shift and alt. Is it possible to detect cmd in mac? That can be a common key modifier for shortcuts in MacOS. Thanks!

mabe02 commented 3 years ago

Isn't it using the same key modifiers as either ALT or CTRL? Any idea how it alters the characters read from the input stream? I don't have a Mac so I can't test, but I'm happy to add it if it's different from what we have.

ajh123 commented 3 years ago

The command key is also know as the meta key, on windows its the windows key. Also it's just like using AlT or ctrl

mabe02 commented 3 years ago

Ok, as I still don't have a mac to test this on, please check out the source code and run the InputTest program (which is included in the test directory). It's important you run the program in a proper terminal emulator and not the IDE's console window. This will read and print back whatever you put on STDIN. So, try to press A, then CTRL-A, then ALT-A and then CMD-A. Copy and paste the output here so we can see how it differs when using CMD.

rockwotj commented 3 years ago

Okay so I tried this out and it turns out by default the cmd key on mac is not sent to the terminal, and instead the esc key is mapped as meta. There is an option to change alt to be meta, but it seems there really isn't a special mapping for this. Thanks for looking into this and for this great library, but I don't think there is anything to do here.