Skip to content

Arrow Keys Not Working on Windows #91

@li20034

Description

@li20034

When xmp-cli is built & run on Windows (using msys2 + mingw64), the arrow keys do not do anything.

The change below is my attempt to fix it, which seems to work (tested on Windows 10 & 11 with both cmd and Windows Terminal).
Also tested on Ubuntu 24.04 to ensure that it does not break anything there.

diff --git a/src/commands.c b/src/commands.c
index 7673f8d7..9620ab5d 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -148,10 +148,27 @@ void read_command(xmp_context handle, const struct xmp_module_info *mi, struct c
 	int cmd;
 
 	cmd = read_key();
-	if (cmd <= 0)
+	if (cmd == -1)
 		return;
 
 	switch (cmd) {
+#ifdef WIN32
+	case 0x00:
+	case -0x20: // 0xe0
+		cmd = read_key();
+		switch (cmd) {
+		case 0x48:
+			goto cmd_next_mod;
+		case 0x50:
+			goto cmd_prev_mod;
+		case 0x4d:
+			goto cmd_next_pos;
+		case 0x4b:
+			goto cmd_prev_pos;
+		}
+
+		break;
+#endif
 	case 0x1b:		/* escape */
 		cmd = read_key();
 		if (cmd != '[')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions