Page 1 of 1

Output text

Posted: Wed Jun 21, 2017 7:46 pm
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 "ч".

Re: Output text

Posted: Fri Jun 23, 2017 12:40 pm
by Skere
Are you talking about text inputs, or changing the key when a key is pressed for the callback?

Re: Output text

Posted: Fri Jun 23, 2017 2:42 pm
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.

Re: Output text

Posted: Sun Jun 25, 2017 9:46 am
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.

Re: Output text

Posted: Sun Jun 25, 2017 10:58 am
by MasterLee
Do you wan't to change Keyboard Layout?
The Microsoft Keyboard Layout Creator

Re: Output text

Posted: Sun Jun 25, 2017 1:02 pm
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

Re: Output text

Posted: Tue Jun 27, 2017 7:47 pm
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.