BlackWaspTM

This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

Input / Output
.NET 2.0+

Checking Scroll Lock Status

The Scroll Lock key is a toggle key that behaves in a similar manner to Caps Lock and Num Lock. The principle purpose for Scroll Lock is to fix the position of the caret, or text cursor, and instead scroll the window when the arrow keys are pressed.

Control Class

The Scroll Lock key is an infrequently used key on most computer keyboards. Its purpose changes between programs, although for a large amount of software it has no effect on input. One common use is to fix the location of the caret, or flashing text cursor, or to fix the position of some other location indicator. In such a situation, when Scroll Lock is enabled and the arrow keys are pressed, the active window simply scrolls. This type of behaviour can be seen in Microsoft Excel.

In previous articles we have seen how to use the Console and Control classes to retrieve the status of the Caps Lock and Num Lock keys. The Console class does not provide a method or property that returns the status of Scroll Lock so that you can change the operation of your program in response to it. Instead, you must use Control class. This requires the use of the System.Windows.Forms namespace.

To check the status of the key, use the IsKeyLocked method, passing the details of the scroll lock key as follows:

if (Control.IsKeyLocked(Keys.Scroll))
{
    MessageBox.Show("Scroll Lock is on!");
}
29 November 2008