Opinion for updating section material: The difference in "Return" and "Enter" keys

Just wanted to offer a suggested addition from following along with the “Using if…” video:

(brackets are used to emphasize the key.

Most PC keyboards have an [Enter] key where you would find the [Return] key on a MAC keyboard (there are some brands who do properly label it [Return] for PC’s, but are not in the majority). Additionally, some PC keyboards include the numeric keypad on the right-hand side of their boards, wherein a second [Enter] key can be found.

To a novice programmer it may be a bit confusing, especially when using a standard PC keyboard layout which does not have the numeric keypad (i.e. laptops).

I suggest expounding a little on the [Enter] vs [Return] button differences, and the keycodes which could get confused:

Keycode.Return is for when you are using the [Return] key on a MAC, or the [Enter] key which is tandem to the alphabet (found above the right-hand [Shift] key the on a PC keyboard;

Keycode.KeypadEnter is for when you want to use the [Enter] key which is tandem to the 9-digit keypad, if your keyboard includes one. Using this will not register if the main [Enter] key is pressed.

1 Like

This concept that the keys are indeed different made me realize that perhaps it’s a good practice to use both in the statement. so KeyCode.Return OR KeyCode.KeypadEnter could both be used. This approach would cover both keys and you would get the same output no matter which key was used. I am a beginner programmer so I’m sure there is a much better way to do this but I just do not know it yet.

I did add this to my code while watching this video to see if it would work. I couldn’t get the | or || to work in 1 statement with what I have learned so far, but adding another if statement for Keypad.Enter worked.
My pc keyboard has both keys labeled “Enter” so I didn’t realize they were separate.

if (Input.GetKeyDown(KeyCode.Return)) {
print(“I WON!!”);
}
if (Input.GetKeyDown (KeyCode.KeypadEnter)) {
print(“I WON!!”);
}

Privacy & Terms