Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent scrolling with arrow keys but NOT the mouse?

Since I'm using jQuery, any solution via that would work too. Ideally, I'd like to know both, though.

I already have the arrow keys bound to another function on my page (using jQuery), but having them cause the page to scroll in addition to that, causes me problems.

I may have known this at one time, but I don't remember it anymore.

like image 395
Daddy Warbox Avatar asked Jun 29 '09 04:06

Daddy Warbox


People also ask

What is the shortcut key for Scroll Lock?

The official Microsoft shortcut for Scroll Lock is Shift + F14.

How do I turn on Scroll Lock?

The scroll lock can be turned on or off by pressing the “Scroll Lock” or “ScrLk” key on the keyboard. This key may not be available on all physical keyboards. However, it is available on all virtual keyboards.

What is mouse Scroll Lock?

Sometimes abbreviated as ScLk, ScrLk, or Slk, the Scroll Lock key is found on a computer keyboard, often located close to the pause key. The Scroll Lock key was initially intended to be used in conjunction with the arrow keys to scroll through the contents of a text box.


1 Answers

Adding document level keypress handler does the trick!

var ar=new Array(33,34,35,36,37,38,39,40);  $(document).keydown(function(e) {      var key = e.which;       //console.log(key);       //if(key==35 || key == 36 || key == 37 || key == 39)       if($.inArray(key,ar) > -1) {           e.preventDefault();           return false;       }       return true; }); 
like image 61
TheVillageIdiot Avatar answered Oct 07 '22 19:10

TheVillageIdiot