• 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!

SOLVED Use upper- and lowercase to detect key input like in keyboard_check()

hello,

Long story short, I try to make a gametable wich can be played with 8 people simultaneously. The input of the table/players are arcade styled buttons, who are converted with a USB keyboard encoder to letters and numbers.
So simple math gives me 8 inputs for 1 player, 8 * 8 = 64, so that would mean I need every keycode both upper- and lowercase to detect player input.
as we know keyboard_check(ord()) only accept uppercase. I even tried to replace the ord() function, with actual keycodes for a lowercase letter, but no luck, why this is as it is I don't know 🙃
So the actual question is, is there an easy work arround, I allready tried the search function, but nothing showed up or I'm using the wrong search keywords.

thanks!
 
That won't help me :-(

Example :

aPlayer 1 UPAPlayer 4 UP
bPlayer 1 DOWNBPlayer 4 DOWN
cPlayer 1 LEFTCPlayer 4 LEFT
dPlayer 1 RIGHTDPlayer 4 RIGHT
ePlayer 1 Button 1EPlayer 4 Button 1
fPlayer 1 Button 2FPlayer 4 Button 2
gPlayer 1 Button 3GPlayer 4 Button 3
hPlayer 1 Button 4HPlayer 4 Button 4
iPlayer 2 UPIPlayer 5 UP
jPlayer 2 DOWNJPlayer 5 DOWN
kPlayer 2 LEFTKPlayer 5 LEFT
lPlayer 2 RIGHTLPlayer 5 RIGHT
mPlayer 2 Button 1MPlayer 5 Button 1
nPlayer 2 Button 2NPlayer 5 Button 2
oPlayer 2 Button 3OPlayer 5 Button 3
pPlayer 2 Button 4PPlayer 5 Button 4
qPlayer 3 UPQPlayer 6 UP
rPlayer 3 DOWNRPlayer 6 DOWN
sPlayer 3 LEFTSPlayer 6 LEFT
tPlayer 3 RIGHTTPlayer 6 RIGHT
uPlayer 3 Button 1UPlayer 6 Button 1
vPlayer 3 Button 2VPlayer 6 Button 2
wPlayer 3 Button 3WPlayer 6 Button 3
xPlayer 3 Button 4XPlayer 6 Button 4
yY
zZ

I need all 26 + 26 letters upper and lowercases as input
 
Last edited:
There is no such thing as a capital A key or a lowercase A key, just an A key. Shift used to be a keycode modifier on much older hardware, but that is no longer the case. The simplest solution would be to use keys other than the letters. Space, Backspace, 0-9, the F1-12 keys, Home/Insert/Delete, all the numpad keys, etc. You should have more than enough.

No idea if your hardware can support this. If it doesn't, you should try something that will better support multiple inputs, like wiring up the arcade buttons to directinput controller boards.
 

TsukaYuriko

☄️
Forum Staff
Moderator
There are no keycodes for lowercase letters. There are key codes for letters in general. The key code for "A" is not a keycode for uppercase A, but for the key labeled "A" on your keyboard. You don't even get an uppercase A when you press this key; You get a lowercase one. You only get an uppercase one when you also press Shift.

Continue this thought a bit further and you'll realize that if you were to continue trying to make this work the way you are envisioning, you'll find yourself at a dead end where player 2's input will either also trigger player 1's input, or player 1 and player 2 will not be able to enter the same input at the same time.

Abandon this plan. Use different keys. You have more than just 26 letters. 10 numbers, I can count at least 12 symbols, 10 on the numpad, 6 with insert, home, delete, end, page up and page down... and if you need more than 64, you have 12 more with F1~F12, 4 more with the arrow keys...
 
S

sivispacem

Guest
Couldn't you predicate all inputs for players with a conditional? Such as All of player 1's inputs (key events) need this key held first:
GML:
if(keyboard_check(vk_control))
{
    if(keyboard_check(vk_) //or put this in a key press event, where ctrl needs to be held on key "A"'s key press event
}
One player has ctrl, one has alt, one has tab, etc.

Then all players can have the same 8 input keys and just a different modifying event.

?
 
Thank you for thinking with me. Is sureley know
Couldn't you predicate all inputs for players with a conditional? Such as All of player 1's inputs (key events) need this key held first:
GML:
if(keyboard_check(vk_control))
{
    if(keyboard_check(vk_) //or put this in a key press event, where ctrl needs to be held on key "A"'s key press event
}
One player has ctrl, one has alt, one has tab, etc.

Then all players can have the same 8 input keys and just a different modifying event.

?
I think that that would work if they must play one at the time, but again each other would be totaly chaos, take player 1 = ALT and player 2 CTRL, if player 1 would press A, and player 2 press B, = ALT+A and CTRL+B, that would mean that ALT+B and CTRL+A would also be pressed, because the keys A,B, ALT and CTRL are pressed at the same time. But thank you for thinking with me!!
 
Couldn't you predicate all inputs for players with a conditional? Such as All of player 1's inputs (key events) need this key held first:
GML:
if(keyboard_check(vk_control))
{
    if(keyboard_check(vk_) //or put this in a key press event, where ctrl needs to be held on key "A"'s key press event
}
One player has ctrl, one has alt, one has tab, etc.

Then all players can have the same 8 input keys and just a different modifying event.

?
If you're checking non-alphanumeric keys, why not just use them as inputs?
 
There are no keycodes for lowercase letters. There are key codes for letters in general. The key code for "A" is not a keycode for uppercase A, but for the key labeled "A" on your keyboard. You don't even get an uppercase A when you press this key; You get a lowercase one. You only get an uppercase one when you also press Shift.

Continue this thought a bit further and you'll realize that if you were to continue trying to make this work the way you are envisioning, you'll find yourself at a dead end where player 2's input will either also trigger player 1's input, or player 1 and player 2 will not be able to enter the same input at the same time.

Abandon this plan. Use different keys. You have more than just 26 letters. 10 numbers, I can count at least 12 symbols, 10 on the numpad, 6 with insert, home, delete, end, page up and page down... and if you need more than 64, you have 12 more with F1~F12, 4 more with the arrow keys...
Well I thought also for not using the uppercase letters, but I want to build it future proof, It could be that we go to 10 players or more. You say that the keycode for "A" is not the Keycode for uppercase "A", but ord("A") gives me 65 wich is the decimal ASCII value of A, thats why I'm a little dissapointed that we can't use all the decimal ASCII values like 'a' is 97 in the keyboard_check function. But it will have its reasons, why its done that way :-D.
And thats were my autism kicks in , if we press 'a', in code we must use "A" :-D
I Will play with it some more tonight , yesterday I tested with keyboard_lastchar() but it was not what I expected. Thanks for thinking with me!
 
There is no such thing as a capital A key or a lowercase A key, just an A key. Shift used to be a keycode modifier on much older hardware, but that is no longer the case. The simplest solution would be to use keys other than the letters. Space, Backspace, 0-9, the F1-12 keys, Home/Insert/Delete, all the numpad keys, etc. You should have more than enough.

No idea if your hardware can support this. If it doesn't, you should try something that will better support multiple inputs, like wiring up the arcade buttons to directinput controller boards.
The directinput controller board is also open for option, but I think there is no guarantee, that gamepad device ID 1, will be 1 the next time. But that is really the last backup option to go the controller way :-D
 
shady workaround:
Have a global variable named global.cap_lock set to false at game start.
If player pressed caps lock, toggle this bool.
If either caps_lock is true or shift is held, it's an uppercase letter.
Wont work tho if the player boots up the game with caps lock on, but yeah... consider it the best you can get in GM anyway (to my knowledge)

The directinput controller board is also open for option, but I think there is no guarantee, that gamepad device ID 1, will be 1 the next time. But that is really the last backup option to go the controller way :-D
I have a tutorial on here about that and how you can keep the same gamepad "assigned" to a player. It should be completed today, but there's enough inthere to get you started if it's something that interests you. Basically, it just stores the GUID of the controller in a variable.
 
shady workaround:
Have a global variable named global.cap_lock set to false at game start.
If player pressed caps lock, toggle this bool.
If either caps_lock is true or shift is held, it's an uppercase letter.
Wont work tho if the player boots up the game with caps lock on, but yeah... consider it the best you can get in GM anyway (to my knowledge)


I have a tutorial on here about that and how you can keep the same gamepad "assigned" to a player. It should be completed today, but there's enough inthere to get you started if it's something that interests you. Basically, it just stores the GUID of the controller in a variable.
Well the caps lock will not help in my case, because the keyboard encoder device, will output the letter directly like 'A', not like SHIFT + 'a' or CAPSLOCK ON + 'a'.

Maybe I must rephrase my question. I'm looking for a way to make my own keyboard_check() , one who accepts all the common ASCII values and not just a certain range :-D So basicly rerwrite the function :-D

I'm interrested in your tutorial, because thats maybe the way to add infinite players, but will cost me more in hardware :-D I think I can use 1 controller for 2 players. I may use right and left trigger to be left and right for player 2... ect :-D
 
@Stingertje I reread the OP, and think about this:
1- If all 8 players play simultaniously, it just wont work. No real estate for hands + keyboard ghosting will make it a not-fun experience. What if my key is "a" and yours is "A"? We fight?
2- If it's turn-based, why not everyone uses the same keys?

Seems there is no reason to try to reinvent the wheel here...
 
@Stingertje I reread the OP, and think about this:
1- If all 8 players play simultaniously, it just wont work. No real estate for hands + keyboard ghosting will make it a not-fun experience. What if my key is "a" and yours is "A"? We fight?
2- If it's turn-based, why not everyone uses the same keys?

Seems there is no reason to try to reinvent the wheel here...
to answer 1 :

I use a piece of hardware who has 56 inputs. You can say this emulates a keyboard. So I can program that board that input 1 emulates 'a', input 2 emulates 'A' .... This board is made for arcade cabinets, those button bashing things, where its common to have multiple key/button presses at the same time . so the board can handel this.

I-PAC 4 in key mode breaks through the USB simultaneously-pressed-switch limit of 6 switches (plus ctrl,alt,shift) which afflicts all USB keyboard devices. This is beacuse it has inbuilt full native USB support, and does not rely on an add-on adaptor.
  • Does not use a matrix - no ghost keys.
  • Does not use a scanning method which causes a variable delay. Each input has it's own dedicated connection into the on-board CPU .
  • Fast running interrupt-driven software gives much better response than a standard keyboard controller. Key debounce uses a state method for each key. No delays between keys depressed at the same time. (essential for fighting games).

to answer 2 : its not turn based !!!
 
I use a piece of hardware who has 56 inputs. You can say this emulates a keyboard. So I can program that board that input 1 emulates 'a', input 2 emulates 'A' .... This board is made for arcade cabinets, those button bashing things, where its common to have multiple key/button presses at the same time . so the board can handel this.
Funny 'cause I pretty just make game for my DIY arcade cabinet which has (cheap) DIY joysticks. I know some of the high-end commercial fight stick are the bomb, so they may indeed not have ghosting issues.
If I don't use some kind of input extension tho, it's a pain to make it work... the built-in stuff works good for mouse/keyboard and XInput gamepads, but if you venture outside that, make yourself a lunch, 'cause you will be home late, mate! 😂
 
Funny 'cause I pretty just make game for my DIY arcade cabinet which has (cheap) DIY joysticks. I know some of the high-end commercial fight stick are the bomb, so they may indeed not have ghosting issues.
If I don't use some kind of input extension tho, it's a pain to make it work... the built-in stuff works good for mouse/keyboard and XInput gamepads, but if you venture outside that, make yourself a lunch, 'cause you will be home late, mate! 😂
My modified arcade cabinet allready uses an extension from the same makers of the IPAC-4, so I'm allready on dessert for the hardware part 🙃
 
Top