openclaw - ✅(Solved) Fix process send-keys arrow keys not working in application cursor key mode [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#51488Fetched 2026-04-08 01:10:33
View on GitHub
Comments
1
Participants
2
Timeline
19
Reactions
0
Author
Participants
Timeline (top)
referenced ×15closed ×1commented ×1cross-referenced ×1

Root Cause

For example, when playing a snake.py game in a PTY session, the agent cannot control the snake's direction because arrow keys are not encoded correctly.

Fix Action

Fixed

PR fix notes

PR #51490: fix(process): auto-detect PTY cursor key mode for send-keys

Description (problem / solution / changelog)

Fixes #51488

Solution

  1. Detect smkx/rmkx before sanitizeBinaryOutput

    • Scan PTY output for smkx (\x1b[?1h) / rmkx (\x1b[?1l) sequences
    • Update ProcessSession.cursorKeyMode state before sanitization strips ESC
  2. Encode arrow keys based on current mode

    • encodeKeySequence(request, cursorKeyMode) accepts mode parameter
    • application mode → SS3 sequences (\x1bOA/B/C/D)
    • normal mode → CSI sequences (\x1b[A/B/C/D) (default)

Files Changed

  • src/agents/bash-process-registry.ts - track cursorKeyMode in ProcessSession
  • src/agents/bash-tools.exec-runtime.ts - smkx/rmkx detection before sanitization
  • src/agents/bash-tools.process.ts - send-keys uses detected mode
  • src/agents/pty-keys.ts - encode arrow keys with correct sequence
  • src/agents/bash-process-registry.test.ts - cursorKeyMode property tests
  • src/agents/pty-keys.test.ts - CSI/SS3 sequence encoding tests

Testing

  • Verified with snake.py game - arrow keys correctly control snake direction
  • Unit tests: 17 tests pass (CSI/SS3 sequences, cursorKeyMode property)

Changed files

  • src/agents/bash-process-registry.test.ts (modified, +52/-0)
  • src/agents/bash-process-registry.ts (modified, +2/-0)
  • src/agents/bash-tools.exec-runtime.test.ts (modified, +29/-1)
  • src/agents/bash-tools.exec-runtime.ts (modified, +28/-1)
  • src/agents/bash-tools.process.ts (modified, +12/-6)
  • src/agents/pty-keys.test.ts (modified, +80/-0)
  • src/agents/pty-keys.ts (modified, +33/-3)
RAW_BUFFERClick to expand / collapse

Problem

Agents cannot correctly send arrow keys to background programs via process send-keys when the program uses application cursor key mode. This affects interactive CLI programs like vim, htop, and terminal games.

For example, when playing a snake.py game in a PTY session, the agent cannot control the snake's direction because arrow keys are not encoded correctly.

Programs send smkx (\x1b[?1h) to switch to application mode, expecting SS3 sequences (\x1bOA/B/C/D). But send-keys always sends CSI sequences (\x1b[A/B/C/D) which are for normal mode. Result: arrow keys don't work in application mode.

Technical Background

DECCKM (DEC Cursor Key Mode):

  • smkx (\x1b[?1h\x1b=) → application mode → SS3 sequences (\x1bOA/B/C/D)
  • rmkx (\x1b[?1l\x1b>) → normal mode → CSI sequences (\x1b[A/B/C/D)

extent analysis

Fix Plan

To fix the issue, we need to modify the send-keys functionality to send SS3 sequences when the program is in application cursor key mode.

Step-by-Step Solution

  • Detect when a program switches to application mode by listening for the smkx sequence (\x1b[?1h).
  • When in application mode, modify the send-keys function to send SS3 sequences (\x1bOA/B/C/D) for arrow keys instead of CSI sequences (\x1b[A/B/C/D).
  • Example code snippet in Python:
def send_arrow_key(key):
    if in_application_mode:
        # Send SS3 sequence
        if key == 'up':
            return b'\x1bOA'
        elif key == 'down':
            return b'\x1bOB'
        elif key == 'right':
            return b'\x1bOC'
        elif key == 'left':
            return b'\x1bOD'
    else:
        # Send CSI sequence
        if key == 'up':
            return b'\x1b[A'
        elif key == 'down':
            return b'\x1b[B'
        elif key == 'right':
            return b'\x1b[C'
        elif key == 'left':
            return b'\x1b[D'

# Example usage:
in_application_mode = True  # Set based on detection of smkx sequence
print(send_arrow_key('up'))  # Output: b'\x1bOA'

Verification

To verify the fix, test the send-keys functionality with a program that uses application cursor key mode, such as vim or a terminal game. Ensure that arrow keys are sent correctly and the program responds as expected.

Extra Tips

  • Make sure to properly detect the smkx and rmkx sequences to switch between application and normal modes.
  • Consider adding logging or debugging statements to verify the correct sending of SS3 and CSI sequences.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING