0

I have an application which uses the microsoft webbrowser class ( IE activex ). I'm trying to bind the keydown event and add custom control to the arrow keys, but the keydown event is not fired when using the arrow keys.

I tried following code to capture the keydown event:

$(document).keydown(function(e){   
alert("keydown");  });

$("#element").keydown(function(e){   
alert("keydown");  });

document.onkeydown = function(evt) {
  evt = evt || window.event;
  var keyCode = evt.keyCodeq
  if (keyCode >= 37 && keyCode <= 40) {
      alert("ok");
      return false;
  }
};

The keydown event works, delete key by example, but not when using the arrow keys. When I use the arrow keys in the activex browser, the document scrolls, but it's not possible to add custom control.

In regular IE (non activex) everything works fine.

Any suggestions?

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
  • possible duplicate : http://stackoverflow.com/questions/1402698/binding-arrow-keys-in-js-jquery – n00b Mar 10 '11 at 09:21

1 Answers1

1

Actually there is nothing to do much.

1.

<input type="text" id="test_element">

2.

<script type="text/javascript">
$(function(){
 $("#test_element").keydown(function(e){
  switch(e.which){
   case 37: movement = 'left'; break;
   case 38: movement = 'up'; break;
   case 39: movement = 'down'; break;
   case 40: movement = 'right'; break;
   default: movement = false; break;
  }
  if(movement){
    alert("You just clicked "+movement+" arrow key");
  }
 });
});
</script>
Eddie
  • 195
  • 1
  • 3
  • 14
  • This is correct, when I use regular IE When I call my webpage in the webbrowser control (activex) and I use the arrow keys in #test_element nothing happens Example: http://dl.dropbox.com/u/399104/screenshots/2011-03-10_1041.swf First screen = IE8 Second screen = webbrowser control in my application – Joris W Mar 11 '11 at 10:27