Terminal doesn't respond to keypresses
See original GitHub issueI can’t seem to get input from a Terminal
when using xterm.js in a html page. I apologize in advance if this is a silly error on my end, but I cannot figure out what I did wrong.
Details
- Browser and browser version: Google Chrome | 84.0.4147.89 (Official Build) (64-bit)
- OS version: Ubuntu 20.04 LTS x86_64
- xterm.js version: 4.8.1
Steps to reproduce
- Put this into a file:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Broken :(</title>
<link rel="stylesheet" href="node_modules/xterm/css/xterm.css" />
<script src="node_modules/xterm/lib/xterm.js"></script>
</head>
<body>
<div id="terminal"></div>
<script type = "text/javascript">
var term = new Terminal();
term.open(document.getElementById('terminal'));
term.writeln('Hello World!');
term.onKey = (key, ev) => {
console.log(`Key entered: ${key}`);
}
</script>
</body>
</html>
- Open it in browser (same behavior also observed when using a basic HTTP server).
- There is a properly styled terminal but I cannot type in it. Nothing happens visually. There is also no output in the console.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
The Unresponsive Terminal - Learning the UNIX ... - O'Reilly
If you can type commands, but nothing happens when you press RETURN, try pressing LINE FEED or typing CTRL-J. If this works, your...
Read more >If your Mac doesn't respond to key presses - Apple Support (KG)
Choose Apple menu > System Settings, click Accessibility in the sidebar, then click Pointer Control on the right. (You may need to scroll...
Read more >How to Fix Can't Type in Terminal Issue in Linux
Try pressing Ctrl + Z in your non-responding terminal to suspend any active task.
Read more >keyboard - What is the most probable cause of terminal freeze ...
If a terminal is frozen but not the rest of the GUI, then the first place to check is if you typed Ctrl...
Read more >Fix Keyboard Input on Terminals - Please - LeoNerd
I want terminal keypresses to Just Work. What do I mean Just Work? ... Explain that, because their program doesn't correctly handle these ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@anatoly314 I think it’s like this because the keyboard (the IME) is hanging onto the words until they are committed. This is similar to how other language keyboards work, in the below image the Japanese characters are not part of the textarea just yet, but part of the “composition” until committed.
Proper mobile support would really need some more thinking on how to make the experience nice, plus you would likely require a bunch of key/modifier buttons to do things like holding ctrl and pressing esc. Right now it’s out of scope for the lib until we decide to tackle https://github.com/xtermjs/xterm.js/issues/1101
term.onKey is a function:
Also you should typically be using
onData
instead.