How to simulate keyboard key press?

18 views
Skip to first unread message

Shuo-Peng Liao (廖碩鵬)

unread,
Feb 25, 2015, 12:54:31 PM2/25/15
to tele...@chromium.org
Hi Telemetry team,

I'm setting up a Google Maps workload. One basic action is to pan the maps. At first I search Telemetry source tree. I found several actions, like scroll and gesture, but no keyboard. Then I tried to dispatch keydown/keyup event for arrow left/right/up/down using Telemetry's ExecuteJavaScript(). But my script seems not working:

function keyDown(key_code) {
   var event = document.createEvent("KeyboardEvent");   
   // Chromium hack
   Object.defineProperty(event, "keyCode", {
       get: function() { return this.keyCodeVal; }});
   Object.defineProperty(event, "which", {
       get: function() { return this.keyCodeVal; }});
   event.initKeyboardEvent("keydown", true, false, window, false, false, false, false, 0, key_code);
   event.keyCodeVal = key_code;
   document.dispatchEvent(event);
}

Then call keyDown(40) to expect Maps tile goes down. But it seems not working on Google Maps.

What's the right way to simulate keystroke using Telemetry? Perhaps we can add keyboard action in telemetry/page/actions. 

Best,
Dean


Reply all
Reply to author
Forward
0 new messages