VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Change the Keyboard Speed and Delay

by Joshua Moore (1 Submission)
Category: Games
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (38 Votes)

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.

Assumes
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

Rate Change the Keyboard Speed and Delay

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

Download this snippet    Add to My Saved Code

Change the Keyboard Speed and Delay Comments

No comments have been posted about Change the Keyboard Speed and Delay. Why not be the first to post a comment about Change the Keyboard Speed and Delay.

Post your comment

Subject:
Message:
0/1000 characters