Apple allows many kinds of input methods on the iPhone, like multi touch screen, the amazingly usable on-screen keyboard, the accelerometer, the GPS/cell tower/WiFi tracking, the camera and even 4 real buttons and a switch which all allow interacting with applications running on the phone. But there are some things which would require other means of input, like a real keyboard for typing more than a URL or Twitter’s 140 characters or a gamepad for playing NES games in the emulator.
There are 3 possible ways keyboards, game pads or other input devices could be connected to the iPhone. I’ll first describe these hardware solutions and then ponder a bit on the software side.
Cabled keyboards

When the Newton MessagePad, Apple’s previous touch-screen based device, hit the market, one of the accessories from Apple was a keyboard for typing longer texts. It was connected to the Newton’s serial port. Since the keyboard was connected by a cable, both the MessagePad and the keyboad lay flat on the table, taking much space and making the MP difficult to read due to the flat angle.

For the Palm Pilot, basically a cheaper, smaller version of the Newton, 3rd-party-developers released foldable keyboards with a built-in serial connector/stand, so that the Pilot could be put into the keyboard, turning the combination into something like a laptop form-factor, where the view angle was straight on the display. The iPhone also features a serial port, but no official or unofficial keyboard has been announced yet.
Infrared keyboards

Since Palm developed a liking for exchanging the bottom connector layout or even producing models without one altogether, new foldable keyboards with a freely positionable IR diode were produced that promised to survive the switch to a new Palm model. The switch to light-based, non-cabled connections brought one disadvantage, by the way: Now the keyboard had to have its own power supply, normally a AAA battery, that tended to be empty whenever needed.

Since the foldable IR keyboards are still quite pricy, a cheaper way to go might be getting one of the keyboards for VCR-like multimedia PCs from 10 years ago, which now sell for about 4€. But there’s still one problem with this solution, the iPhone has no IR receiver. In another post, I’m dealing with how to connect one.
Bluetooth keyboards

The third category is Bluetooth keyboards. There’s a lot of foldable ones, and Apple also offers a very nice and portable Bluetooth keyboard for their line of Macintosh computers.

A very cool and portable bluetooth keyboard is this lighted-sized device which laser-projects a full-sized keyboard on any flat surface and costs around 100€. The iPhone does have a Bluetooth module for connecting to wireless headsets, but connecting the Apple Wireless Keyboard or any other keyboard is not supported yet, but it might just be in the next firmware version.
Game Pads

The first game pads for early consoles had no logic at all, requiring a seperate line for every button and direction, and later they were interfaced by custom protocols. Those gamepads would need to be interfaced using custom hardware like a microcontroller-based circuit. Game pads compatible with RS-232, the serial protocol that is a standard on many, many computers and devices, are seldomly found. But luckily, Nintendo decided to use standard Bluetooth protocol on their controllers for their newest console, the Wii. Although this controller is not officially supported of course, software like Wiiji or DarwiinRemote exists to use the Wiimote on Macintosh computers, which use much of the same system software.
Software
No matter what method you use to connect a keyboard or other input device to the iPhone, a driver will be needed to do anything useful. I’ll look into this topic as soon a time allows, updating this post.
If you do not want to hack anything, you could just wait for this keyboard with included iPhone driver from MacAlley, whenever it will really hit the market. Another project develops a frame which actually turns the iPhone into a game pad, but this also isn’t available yet.