How to remove default behaviour of key board events |
How to remove default behaviour of key board events |
kuppi |
Nov 17 2008, 09:49 AM
Post
#1
|
Group: Members Posts: 4 Joined: 6-November 08 Member No.: 7,060 |
How do we handle key board events with our own code?
i am using function keyboardEntry(evt) { var evt = (evt) ? evt : ((event) ? event : null); var charcodevalue = evt.keyCode; getSlotPortNext(charcodevalue); } document.onkeyup = keyboardEntry; to capture key board event. and i am giving my own functionality in the function getSlotPortNext(); This function i have writen to capture up arrow and down arrow keys. If i press up arrow key, it have to select the image above. and if down arrow key is pressed, it have to capture the below image. Now my problem is when i try to press up arrow key, it is doing the default behaviour(goes up) and then does my functionality(set scrollbar with respect to the object selected.) There is some kind of flickering. i tried by using prevent default method also. function keyboardEntry(evt) { var evt = (evt) ? evt : ((event) ? event : null); var charcodevalue = evt.keyCode; evt.preventDefault(); getSlotPortNext(charcodevalue); } document.onkeyup = keyboardEntry; Still it is not working fine. some one please help me in solving this. |
Christian J |
Nov 17 2008, 12:00 PM
Post
#2
|
. Group: WDG Moderators Posts: 9,663 Joined: 10-August 06 Member No.: 7 |
when i try to press up arrow key, it is doing the default behaviour(goes up) You can normally supress the default behavior with "return false", but when I tested the supression only seemed to work with onkeydown in MSIE and Safari (Windows), while Opera needed onkeypress. Don't know about non-Windows browsers. See also http://www.quirksmode.org/js/events_properties.html#key When testing, make sure that the browser reloads the test page properly (since the "return false" may disable the F5 key too). Also users may become annoyed if they can't use the arrow keys for ordinary scrolling. |
Lo-Fi Version | Time is now: 6th May 2024 - 07:03 AM |