简体   繁体   中英

Send Ctrl+P through serial with JSSC

Im working on a program for work. The program is just a terminal for connecting to devices via serial and in this specific device, it requires you to press Ctrl and P simultaneously to enter a menu. At the moment, my temporary solution is to use JSwing's Robot, which is exactly what i DONT want to do.

i thought if i sent SerialPort.writeInt(KeyEvent.VK_CONTROL + KeyEvent.VK_P); it would perhaps do the trick. I tried writing KeyEvent.VK_CONTROL and KeyEvent.VK_P in their own line but they are sent individually, not together to simulate a "Control-Down->P".

Does anyone know of a possible alternative that isnt Robot? maybe there is a workaround?

KeyEvent.VK_CONTROL is 17
KeyEvent.VK_P is 80

17 + 80 = 97 => not good
17 & 80 = 16 => control-P

So:

SerialPort.writeInt(KeyEvent.VK_CONTROL & KeyEvent.VK_P);
  or
SerialPort.writeInt(16);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM