11
2
Write a program which generates keyboard events which type Hello, World!
.
It doesn't have to be platform-independent.
It can't leave any keys pressed. For example, in Java, Robot.KeyPress('H');
will leave H
pressed, so you must release it with Robot.KeyRelease('H');
You may assume that the caps lock is off when your program is run. Capital letters can be typed either by holding shift and pressing the letter, or by toggling caps lock. For the !
, you'll probably have to use the shift method.
Shortest code wins.
You can shorten some. Remove
s
(just initializefor(c="H..
), incrementc
in theioctl
,main(D)
to saveint
. Maybe also remove some includes (even hard-codeO_RDWR
andTIOCSTI
). – ugoren – 2013-02-25T14:44:32.150@ugoren Thanks, I'll try them :) – saeedn – 2013-02-26T00:44:57.600
This one is not the shortest. Why is this the accepted answer? (I think it is a nice answer, but I just want to learn how the site works.) – 11684 – 2013-03-11T12:56:33.633
@11684 The author of the shortest answer asked me not to count it, so I accepted the shortest non-trivial answer instead. – cardboard_box – 2013-03-11T23:44:23.620
No need to call
tty
it only works if stdin is a tty, in which case,0
is already an open terminal fd. – Dave – 2013-12-09T08:38:20.713