Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
Convertir la función asíncrona de un paquete para sincronizar

Esta función pasa por todas las matrices de un teclado, le pide al teclado el código clave en cada lugar y lo empuja a la matriz de códigos de teclas de capa. El problema es que device.read() es asincrónico y no pude encontrar una manera de hacerlo sincrónico sin tener un código súper desordenado. El problema es que el archivo console.log() al final (que se devolverá en producción) se activa antes de que el teclado responda y envíe los códigos clave. Sé que existe device.readSync() pero la documentación de nodehid es mala, no pude encontrar cómo usarlo.

 const getLayerKeycodes = (keyboard, layer, rows, columns) => { //array that stores all the keycodes according to their order let layerKeycodes = []; //rows and columns start the count at 0 in low level, so we need to decrease one from the actual number. columns --; rows --; //loop that asks about all the keycodes in a layer const dataReceived = (err, data) => { if(err) { return err; } // push the current keycode to the array // The keycode is always returned as the fifth object. layerKeycodes.push(data[5]); console.log(layerKeycodes); }; for (let r = 0 , c = 0;c <= columns; r ++){ //callback to fire once data is receieved back from the keyboard. if(r > rows){ c++; //r will turn to 0 once the continue fires and the loop executes again r = -1; continue; } //Start listening and call dataReceived when data is received keyboard[0].read(dataReceived); //Ask keyboard for information about keycode // [always 0 (first byte is ignored),always 0x04 (get_keycode),layer requested,row being checked,column being checked] keyboard[0].write([0x01,0x04,layer,r,c]); } console.log(layerKeycodes); }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!