How to emulate arrow keys

40 views
Skip to first unread message

Robert Butera

unread,
Oct 24, 2016, 2:24:01 AM10/24/16
to Yet another Expect for Java
Hi,

I'm using expectit to automate a interaction with  console based application I access over ssh.

Am having trouble figuring out how to send the control characters required to emulate a user pressing the arrow key.

Any guidance would be much appreciated.

Regards
Rob

Alexey Gavrilov

unread,
Oct 24, 2016, 5:13:37 PM10/24/16
to Robert Butera, Yet another Expect for Java
Hi,

What have you tried so far?  Perhaps expect.writeBytes({ 27, '[', 'A’ }) for arrow up will work

Regards,
Alexey


--
You received this message because you are subscribed to the Google Groups "Yet another Expect for Java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-expecti...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robert Butera

unread,
Oct 24, 2016, 9:43:16 PM10/24/16
to Yet another Expect for Java
Thanks that worked.

Was using send() instead of sendBytes()

Rob

jimm...@gmail.com

unread,
Oct 25, 2016, 8:41:16 PM10/25/16
to Yet another Expect for Java, robert...@gmail.com, Alexey1....@gmail.com
Hey Alexey,

On the same note I can get the arrow keys to send using:
[(byte) 0x1b, (byte) 0x4f, (byte) 0x42]; //^[[B

I'm having trouble sending the function keys though:

F5 comes up in my terminal as ^[[15~

This page suggests a lowercase 't'
http://www.programcreek.com/java-api-examples/index.php?source_dir=jopenray-master/src/main/java/com/jcraft/jcterm/EmulatorVT100.java

I've tried
[(byte)0x1b, (byte)0x4f, (byte)0x0F, (byte)0x7E] (the last two bytes are 15 and ~)
and
[(byte)0x1b, (byte)0x4f, (byte)'t']

Any suggestions on how to send the F5 key?

Thanks,
James

jimm...@gmail.com

unread,
Oct 26, 2016, 6:48:30 PM10/26/16
to Yet another Expect for Java, robert...@gmail.com, Alexey1....@gmail.com, jimm...@gmail.com

BTW we figured this out.
[(byte)0x1b, (byte)0x5b, (byte)0x31, (byte)0x35, (byte)0x7e]

The second byte was incorrect. I was using 'O' instead of '['

Alex camlay

unread,
Sep 6, 2023, 8:08:48 AM9/6/23
to Yet another Expect for Java
Hi, 

I'm trying to do a similar thing but for the numbers : 1,2,3...9.

I don't want to write the number but to simulate the numeric keypad.

In your response above, I didn't understand why there is a '[' and a 'A' :( 

Can you help me please ? :)

Best regards,
Alex CAMLAY

Alex camlay

unread,
Sep 6, 2023, 9:12:03 AM9/6/23
to Yet another Expect for Java
I found this useful table with every inputs codes : https://www.gnu.org/software/screen/manual/html_node/Input-Translation.html

I hope it will help others :)
Reply all
Reply to author
Forward
0 new messages