• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How to provide non textual commands using java program...

 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to control remote terminal through java program by providing commands to remote screen through java program.

I am able to give textual commands to remote screen using java program as follows:-

session.getOutputStream().write(("find abc.xml").getBytes());

However I want to pass some nontextual commands though java program such as "CTRL + C" or "ESC" keys on keyboard to remote terminal. How can I do this?

Many thanks in advance...

--Pras
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those keystroke do produce "text" characters but they are "control characters" not printing characters.

This wikipedia article discusses them, scroll down for a table giving the hex values.

You have to "escape" control characters with a \ when creating Java Strings.

\xhh The character with hexadecimal value 0xhh

Bill
 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi William

Thanks for your reply...I gone through document

So for ESC key, is the below statement correct?

session.getOutputStream().write(("\X1B").getBytes());

or

session.getOutputStream().write(("\e").getBytes());


Also how about sending combination of 2 characters? say "CTRL + C" ?

Please provide your input on this.

Many thanks again.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to go back and read that article again.

Also how about sending combination of 2 characters? say "CTRL + C" ?



When you hold down CTRL and press C on a keyboard, the low level operating system turns that into a single control code character which gets sent to the application input. You are NOT sending two characters.

Look at that table again - see the line


That notation ^C is what we use for CTRL + C.

Bill
 
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I may be mistaken but I think when you press multiple keys like CTR + C it adds thier values together into one. And I do literally mean it "adds" them together.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is a mistaken impression presumably derived from the common practice of writing CTRL + C to mean "holding the ctrl key down while pressing C."

The actual keyboard input handler deep down in the operating system keeps track of individual keyboard events which probably look something like this:

Ctrl key down
C key down
C key up
Ctrl key up

The actual data from a modern keyboard does not look a thing like ASCCI codes - back in the days of teletypes it was another story and keys such as ctrl and shift actually modified what the keyboard hardware sent.

Fortunately modern programmers dont have to know about this level.
Bill
 
Get out of my mind! Look! A tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic