Any Programmatic Way to Get Foreign Language Keys?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
parallax7d
Citizen
Posts: 82
Joined: Wed Jul 02, 2014 11:44 pm

Any Programmatic Way to Get Foreign Language Keys?

Post by parallax7d »

I'd like to be able to iterate through a list of all the scancodes, and get all the characters/glyphs for whatever language/layout/etc. the OS is using. This way the game could dynamically support any possible kb layout by printing the correct glyph on the correct key in the custom keybindings interface. Internally it would just use scancodes, but that is hidden from the user.

I tried using love.keyboard.getKeyFromScancode, but it returns 'unknown' for any glyph/key not part of the English keyboard.

Is there any way of getting these from the user's system?

Maybe simulated keypresses passed to love.textinput? Although that wouldn't support several languages whos keyboard just triggers a menu of other characters (Chinese). Looking for a more elegant solution.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Any Programmatic Way to Get Foreign Language Keys?

Post by raidho36 »

I don't agree with that approach. Not being from english-speaking country myself, I absolutely loathe when games display key bindings in my native character set and not in latin. It's bad enough that my locale has letters where US layout has special symbols and so it's inconsistent, displaying local letters for some keys but not for others, being misleading about it simultaneously since local layout has those in different location - many other languages have layout with latin characters but arranged differently such as France IIRC. And then there's japanese, with about 70 kana characters which come in 2 variants, and many different ways to input characters to boot, not to mention kanji which you can't even input directly. And so on and so forth.

All keyboards have a standard QWERTY latin layout on them and all computer users know how to use that layout. You can (and IMO should) stick to that.
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Any Programmatic Way to Get Foreign Language Keys?

Post by zorg »

I'm a bit torn on this question as well;

To reiterate, you do know and do use [wiki]Scancode[/wiki]s instead of [wiki]KeyConstant[/wiki]s in löve. This alone is a better setup for people with non-US layouts.

Regarding lk.getKeyFromScancode, you did only use the scancodes that are on the wiki page, right? anything else won't work. Also, this function only really does one thing: converts a scancode (which is layout independent, for the most part) and gives back a US-layout key constant.

The only way you could achieve this, is if you had, for example, a lua file, with a table, containing mappings for all layout types, between scancodes and "layout-specific" labels. Even layouts that -also- have IME buttons, i do believe have modes where they have some western-type layout, maybe even US-english, but even if they don't, with the exception of the extra IME keys, that may or may not be able to be detected, all other keys should still be detectable... at least with the keyPressed and keyReleased callbacks.

Though you can't really fix lower-level shenanigans some OS-es do because in the past, someone thought it was okay, like my layout having an "alt-gr" key instead of the right-alt, which generates a combination scancode of left-shift&right-alt in that order... meaning you're either hardcoding a fix for this, which is both hard-ish and not really a solution, or just don't allow the usage of these keys... which might be hard to do if you're only relying on tables with scancodes for table keys, and displayable labels as values... since leftshift is first, not right-alt.

Another thing to consider is that keyboard labels, preferred language (and/or OS and program language) and keyboard layouts are 3 totally separate things. I myself prefer english language, hungarian labels and hungarian layout. But i know some people who code and prefer the US layout, even though their keyboard has hungarian labels. You really can't cover every contingency.

Don't really mean to discourage you, but consider this, your program should have a key redefinition system of some kind. The user will go through it control-by-control. They will know what key they pressed.

"Worst case", if you want to really support this: Allow them to also give a label to the scancodes they intend to use, like they press a button to register the new scancode for, i dunno, "moving left", then after that press has been made, ask them (using textinput) for a label that would be shown to them that means that key/scancode/control. If you do go this way, do use the utf8 lib included with löve, since that will be necessary.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
parallax7d
Citizen
Posts: 82
Joined: Wed Jul 02, 2014 11:44 pm

Re: Any Programmatic Way to Get Foreign Language Keys?

Post by parallax7d »

Message received, I'll just stick to the English kb layout and assume the end user is cool with that.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Majestic-12 [Bot] and 54 guests