# Type “Hello, World!”

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.

# C (Linux), 186 bytes

#include<sys/ioctl.h>
#include<fcntl.h>
#include<stdio.h>
main(){char*s="Hello, World!",d[99],*c;fscanf(popen("tty","r"),"%s",d);int D=open(d,O_RDWR);for(c=s;*c;c++)ioctl(D,TIOCSTI,c);}


After applying ugoren's suggestions:

## 111 bytes

main(D){char*c,d[99];fscanf(popen("tty","r"),"%s",d);D=open(d,2);for(c="Hello, World!";*c;)ioctl(D,21522,c++);}

• You can shorten some. Remove s (just initialize for(c="H..), increment c in the ioctl, main(D) to save int. Maybe also remove some includes (even hard-code O_RDWR and TIOCSTI). – ugoren Feb 25 '13 at 14:44
• @ugoren Thanks, I'll try them :) – saeedn Feb 26 '13 at 0:44
• 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 Mar 11 '13 at 12:56
• @11684 The author of the shortest answer asked me not to count it, so I accepted the shortest non-trivial answer instead. – cardboard_box Mar 11 '13 at 23:44
• No need to call tty it only works if stdin is a tty, in which case, 0 is already an open terminal fd. – Dave Dec 9 '13 at 8:38

# AppleScript, 50 bytes

tell app"System Events"to keystroke"Hello, World!"


Thanks to marinus for the suggestion.

• Huh. Looks like you chose the right language for the right job. – cardboard_box Feb 23 '13 at 2:18
• You can shorten it to tell app"System Events"to keystroke"Hello, World!". – marinus Feb 25 '13 at 5:01
• Damnit, I thought of this independently... +1! – 11684 Mar 11 '13 at 12:54

# Autohotkey, 20 bytes

send Hello, World{!}


Please don't count this one. I don't want to cheat out people who have actually done this with a language not meant for sending keystrokes. This answer is just for completion :P

# Emacs Lisp, 34 bytes

(execute-kbd-macro"Hello, World!")

# C in Windows 7, 201 bytes

#include<windows.h>
#include<winable.h>
#define S SendInput(1,&k,28);
int k[7]={1};main(i){char*s="^HELLO, ^WORLD^1";for(i=0;i<16;i++){k[2]=0;if(s[i]>90){k[1]=16;S i++;}k[1]=s[i];S k[2]=2;S k[1]=16;S}}


Program result:

C:\My\Directory>type.exe

C:\My\Directory>Hello, World!


# AutoIt3, 21 bytes

Send("Hello, World!")

• missing comma! It's actually 21 chars – Doorknob Mar 8 '13 at 21:51
• Where is a comma supposed to be? Edit, never mind, lol. – jdstankosky Mar 11 '13 at 20:18

# VBScript, 54 bytes

createobject("wscript.shell").sendkeys "Hello, World!"


# Tcl, 46 bytes

package r Expect;spawn bash;send Hello,\ World


# Expect, 29 bytes

spawn bash;send Hello,\ World

• Tried to do the Tk version, but failed: file with some stuff pastebin.ca/3897417 – sergiol Oct 28 '17 at 23:08

# Ducky Script for USB Rubber Ducky, 22 bytes

String "Hello, World!"


# PowerShell, 55 bytes

(New-Object -c wscript.shell).sendkeys('Hello, World!')


# InstantEXE 3.0, 20 bytes

Keys "Hello, World!"


## Python 3,67 bytes

from pynput.keyboard import*
s=Controller()
s.type("Hello, World!")


No module named pynput on tio