ariya/phantomjs — pull request #287 by n1k0 (2012-07-01 17:39:11+00:00)
Title: Support for keyboard events

**Disclaimer:** this PR is not intended for being merged as is, but rather to start a discussion.

This is (very) basic support for being able to send *native* keyboard events: `keydown`, `keyup` and `keypress`.

This is my first attempt at writing C++, so please forgive any mistake made (feedback welcome.)

Also, I don't much like the look and feel of the API. Basically, right now the `sendEvent` method allows to send keyboard events like this:

```javascript
var page = require('webpage').create();
page.content = '';
page.evaluate(function() {
document.querySelector('input').focus();
});
page.sendEvent('keypress', 65);
page.sendEvent('keypress', 66);
console.log(page.evaluate(function() {
return document.querySelector('input').value; // "AB"
}));
```
What I don't like:

1. we have to use the `focus()` through `evaluate()` trick to get the focus on the element we want to send keys to;
2. the `sendEvent` method signature looks messy; I hesitated to create a new `sendKeyEvent()` method, but then we would also need to rename `sendEvent()` to `sendMouseEvent()` for consistency;
3. there's no way to use char instead of key code;
4. there's no obvious way to directly send a list of chars (a.k.a strings) to the input element.

I've no clue how hard would be to resolve each point of the list above, therefore I'm asking here :)