Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Java program simulating control-z being pressed

Reply
Thread Tools

Java program simulating control-z being pressed

 
 
Per Magnus L?vold
Guest
Posts: n/a
 
      03-05-2004
Hi,
I have tried to figure out how to make my Java program simulate
control-z (^z) being pressed.
The program communicates over the serial port with a modem
/* sample code */
..
..
sp = (SerialPort) port.open("Test", 1000);
ps = new PrintStream(sp.getOutputStream());
..
..
public void sendBytes(String s) {
for (int i = 0; i < s.length(); i++) {
char b = s.charAt(i);
ps.write(b);
}
}
/* end sample code */

My question is this:
How can I make the Java program send the equivalent of control-z to
the modem?
Typing control-z in hyperterminal manually works, but I want the Java
program to do this. I have thought of using:
sendBytes(KeyEvent.CONTROL+"z");
But this doesn't work.

I find in another posting that "control-c has the numerical value of
3"
http://www.google.com/groups?hl=no&l...Bserial%2Bport
....and someone tip'ed me that control-z then might be 26, but that
does not seem to be right.

Hope someone can help me!

Regards,
Per Magnus
 
Reply With Quote
 
 
 
 
Tor Iver Wilhelmsen
Guest
Posts: n/a
 
      03-05-2004
(Per Magnus L?vold) writes:

> ...and someone tip'ed me that control-z then might be 26, but that
> does not seem to be right.


Yes, but most often you will need to send a CRLF pair as well, ie. the
bytes 26, 13, 10. The reason is that the modem or whatever you talk to
at the other end often will collect characters until a whole line has
been entered, then process that.

Also, remember to flush() the output buffer after writing.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Acting like button are being pressed (BUT THEY ARE NOT) Please Help mcsejung Python 2 02-22-2008 03:19 PM
How to intercept Ctrl key - eg Ctrl E being pressed on Java console program Angus Java 5 11-18-2006 04:19 PM
Detect when key is being pressed then released Si Java 3 02-28-2006 07:27 PM
Leave button depressed after being pressed Novice ASP .Net Web Controls 2 06-23-2004 02:55 AM
How to detect that a key is being pressed, not HAS been pressed earlier!?? Rune Python 6 01-29-2004 12:39 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57