Output text

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
GHPL
Prole
Posts: 7
Joined: Wed Jun 21, 2017 7:10 pm

Output text

Post by GHPL »

For example if I press "U" + "right Alt" i got "€". Is it possible to make that in Love2D using another characters (not pre-programmed)?. I want do that if I press "P" + "right Alt" i get "ч".
Skere
Prole
Posts: 6
Joined: Fri Nov 25, 2016 8:21 pm

Re: Output text

Post by Skere »

Are you talking about text inputs, or changing the key when a key is pressed for the callback?
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Output text

Post by zorg »

It's a bit complicated;

if you want more control over things, then handle key presses with love.keypressed and love.keyreleased (and use the scancode parameter!), and just create your own "mapping table" between scancodes and your own symbols... though you'll need extra work to get combining keys to be detected and such.

A bit simpler would be to use love.textinput, and swap those characters out for whatever you want, though some keys or key combinations may map to the same symbol (like the alpha-dash key next to the right shift, and the minus key on the numpad), so you'd still need to use this in conjunction with the above method to actually detect what key was pressed...

OR if you just want russian input, then if your keyboard -is- set to that, love.textinput -will- (or at least should) give you back the correct characters.
For key detection, scancodes still work regardless of keyboard layout.
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.
GHPL
Prole
Posts: 7
Joined: Wed Jun 21, 2017 7:10 pm

Re: Output text

Post by GHPL »

I not only want detecting pressed buttons, I want too writting it like they was on keyboard.
Like that: http://russian.typeit.org/
I'm pressing "i" and get "и". I want make program that will detect when I'm pressing "P" + "right Alt" and it will output "ч" like it was default keyboard combination, like "U" + "right Alt" = "€". I want use that for example in browser.
MasterLee
Party member
Posts: 141
Joined: Tue Mar 07, 2017 4:03 pm
Contact:

Re: Output text

Post by MasterLee »

Do you wan't to change Keyboard Layout?
The Microsoft Keyboard Layout Creator
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Output text

Post by zorg »

Code: Select all

-- Define your own substitutions.
local map = {
    -- ctrl/alt/shift 0-not held, 1- held; key's scancode
    ['000i'] = 'и',
    ['001i'] = 'И',
    -- etc.
}

love.keypressed = function(scancode)
    local ctrl  = love.keyboard.isDown('rctrl','rctrl')   and 1 or 0
    local alt   = love.keyboard.isDown('ralt','lalt')     and 1 or 0
    local shift = love.keyboard.isDown('rshift','lshift') and 1 or 0
    local key   = ('%1d%1d%1d%s'):format(ctrl,alt,shift,scancode)
    -- and finally, use map[key] in whatever way you prefer, and you'll get whatever character you defined above.
end
You can also just override textinput if you want to use that instead.

Code: Select all

local map = {
    -- utf-8 character maps to utf-8 character.
    ['i'] = 'и',
    ['I'] = 'И',
    -- etc.
}

love.textinput = function(text)
    -- use map[text] in whatever way you prefer.
end
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.
GHPL
Prole
Posts: 7
Joined: Wed Jun 21, 2017 7:10 pm

Re: Output text

Post by GHPL »

MasterLee wrote: Sun Jun 25, 2017 10:58 am Do you wan't to change Keyboard Layout?
The Microsoft Keyboard Layout Creator
That's it. Thanks.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Bing [Bot], Google [Bot], Semrush [Bot] and 6 guests