I was wondering if there is a way to simulate pressing an accesskey with JavaScript. It should work with the following html:
<button accesskey="z">click</button>
Here is my approach with jQuery (pressing ALT+Z in Chrome):
var e = $.Event("keypress");
e.which = 90;
e.altKey = true;
$('button').trigger(e);
But it won't work so far. I want to test the accesskey specifically, just clicking the button via JavaScript is not the solution I'm looking for.
I think you are going to have to use something like Selenium to accomplish this. I have read all the literature I can find on the matter and experimented in jsFiddle. The browser treats an accesskey event exactly like a mouseclick. Even if you did manage to trigger it the event metadata all suggests the source was a mouse click so you can't definitively confirm it.
I have attempted to trigger the key combination on all levels of the DOM and with all key event types, this suggests to me that the accesskey functionality is on the browser level and not the API.
[Edited answer, seems like different technology is needed]