Tools Links Login

Change the Keyboard Speed and Delay

This code allows you to change the Keyboard speed (0 to 31) and delay (0 to 3).. useful in games or as an alternative to using the keyboard control panel.

Original Author: Joshua Moore

Assumptions

In your own code use SetFastKeyboard() to change to your new speed and RestoreKeyboard() to change back to thier previous defaults.

Side Effects

On my computer when my old settings are restored they are restored to speed 0 and delay 0.. after much research i determined that the value being read from the API is 0 and 0.. or my variables can't hold the values being returned.. Anyone with more info on the API or the syntax of SPI_GETKEYBOARDDELAY and SPI_GETKEYBOARDSPEED please email me.. :)

API Declarations

Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long
Public Const SPI_GETKEYBOARDDELAY = 22
Public Const SPI_GETKEYBOARDSPEED = 10
Public Const SPI_SETKEYBOARDDELAY = 23
Public Const SPI_SETKEYBOARDSPEED = 11
Public Const SPIF_SENDCHANGE = 1
Public OldKeySpeed As Long
Public OldKeyDelay As Long

Code

Sub SetFastKeyboard()
Dim Retcode As Long
Dim FastKeySpeed As Long
Dim FastKeyDelay As Long
Dim dummy As Long
FastKeySpeed = 31
FastKeyDelay = 0
dummy = 0

Retcode = SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, OldKeySpeed, 0)
Retcode = SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, OldKeyDelay, 0)
Retcode = SystemParametersInfo(SPI_SETKEYBOARDSPEED, FastKeySpeed, dummy, SPIF_SENDCHANGE)
Retcode = SystemParametersInfo(SPI_SETKEYBOARDDELAY, FastKeyDelay, dummy, SPIF_SENDCHANGE)
End Sub
Sub RestoreKeyboard()
Dim Retcode As Long
Dim dummy As Long
dummy = 0
Retcode = SystemParametersInfo(SPI_SETKEYBOARDSPEED, OldKeySpeed, dummy, SPIF_SENDCHANGE)
Retcode = SystemParametersInfo(SPI_SETKEYBOARDDELAY, OldKeyDelay, dummy, SPIF_SENDCHANGE)
End Sub

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 131 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.