• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Obscure shortcuts (non constants)

DesArts

Member
This might be a dead end but is there a good way to create obscure keyboard short-cuts (without a vk constant or ord).

So I think the only way to reliably detect for an obscure character like "[" is using keyboard_string/lastchar while a key is being pressed, since the key code changes depending on keyboard layout so using a number constant is unreliable?

Here's an example of an attempt at a layering short-cut like that in Adobe Illustrator.

Code:
        //ordering
        if (keyboard_check(vk_control))
        {
            if (keyboard_check_pressed(vk_anykey))
            {
                switch (keyboard_lastchar)
                {
                    case "]": 
                        dir = 1;
                    break;
                   
                    case "[": 
                        dir = -1; 
                    break;
                }
            }
        }
However the above doesn't work because the holding of control (or shift) seems to interrupt the string/lastchar being updated some some other issue. Removing the check for control means it just works fine (when not holding control, that is)

So, is there a better way, or should I abandon the "control+" standard for all my other short-cuts to keep consistency?
 

curato

Member
If you are trying to a custom keymapping I would say you need a place to go to change them and make a variables for each function you need to act on and save what needs to be pressed. Then write a function that looks that information up and then used keyboard_check_pressed to see if you are pressing those buttons currently. I don't have sample code on tap but they net effect would be if keyboard_check_pressed(vk_rcontrol) and keyboard_check_pressed(ord("A") then do your function, but you would have the ord values saved in a variable(or array) to insert in the function. If this makes any sense.
 

TheouAegis

Member
Do NOT hardcode keys into your program. Everybody hates playing with the programmer's settings. Let the player determine the controls.
 
B

Bayesian

Guest
since the key code changes depending on keyboard layout so using a number constant is unreliable?
Is this really true? Have you tested this? Try using this with two keyboards with different layouts.
Code:
if(keyboard_check_pressed(219)){
    show_debug_message("[")
}
edit: Ok I figured out that I needed to restart my computer to properly test this myself. You are absolutely right on a US QWERTY key board the code is 219 but on a french keyboard its 221.

Your options are like @TheouAegis said let the user define their keys or you can make an extension that uses hardware scan codes. Or wait for GMS to support scan codes
 
Last edited by a moderator:

DesArts

Member
Yeah I can make them custom which would be good and solve the issue - however I gotta at least have defaults that work right? :p I suppose it's not feasible how I'm thinking.
 
Top