Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

273
Vistas
Only listen onData not onKey when paste with xterm.js

I am writing a tiny web app with an ssh terminal(xterm.js) and some codes block cards alongside. Users can execute commands in terminal by clicking the commands button or just simply type in or paste.

I used onData at the beginning, this API allows me to types in or paste but not able to activate specific event, for example Ctrl + d to disconnect.

onKey seems good. I wrote below codes to attach key event, copy works well but paste does not.

term.attachCustomKeyEventHandler(function (e) {
    // Ctrl + Shift + C
    if (e.ctrlKey && e.shiftKey && (e.keyCode == 3)) {
      var copySucceeded = document.execCommand('copy');
      console.log('copy succeeded', copySucceeded);
      return false;
    }
    if (e.ctrlKey && e.shiftKey && e.keyCode == 'v') {
      var pasteSucceeded = document.execCommand('paste');
      console.log('paste succeeded', pasteSucceeded);
      return false;
    }
  });

Here is my question: onKey and onData both listen on keyboard event. When using both function together, the terminal write twice. It there anyway to listen onData only when paste.

  term.onKey(function (ev) {
    
    const char = ev; 
    console.log(ev)
    if(ev.key.charCodeAt(0)===4){
      //term.dispose();
      socket.disconnect();
    }
      socket.emit('key', ev.key);
  });

  term.onData(function(data){
    console.log(data);
    socket.emit('data',data);
  });
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda