diff --git a/src/g_input.c b/src/g_input.c
index ac901703fe742867b591fc679e1b0469bb0653cf..2efae9cf3e90b0bb491e45577aca63128ccb0c83 100644
--- a/src/g_input.c
+++ b/src/g_input.c
@@ -662,7 +662,14 @@ INT32 G_KeyStringtoNum(const char *keystr)
 		return keystr[0];
 
 	if (!strncmp(keystr, "KEY", 3) && keystr[3] >= '0' && keystr[3] <= '9')
-		return atoi(&keystr[3]);
+	{
+		/* what if we out of range bruh? */
+		j = atoi(&keystr[3]);
+		if (j < NUMINPUTS)
+			return j;
+		else
+			return 0;
+	}
 
 	for (j = 0; j < NUMKEYNAMES; j++)
 		if (!stricmp(keynames[j].name, keystr))