Keyboard repeat rate

  • Thread starter rwboyden via AccessMonster.com
  • Start date
R

rwboyden via AccessMonster.com

Is there a means via VBA code to set the keyboard repeat rate (as is done via
Control Panel - Printers & Other Hardware - Keyboard, Etc.). We'd like to be
able to slow it down in the Got Focus Event for scrolling through a list
control with the Cursor Up/Down keys to allow associated photos to appear as
we scroll, then restore the default repeat rate in the Lost Focus event of
the list control.
 
S

Stuart McCall

rwboyden via AccessMonster.com said:
Is there a means via VBA code to set the keyboard repeat rate (as is done
via
Control Panel - Printers & Other Hardware - Keyboard, Etc.). We'd like to
be
able to slow it down in the Got Focus Event for scrolling through a list
control with the Cursor Up/Down keys to allow associated photos to appear
as
we scroll, then restore the default repeat rate in the Lost Focus event of
the list control.

There's more than one way to achieve the behaviour you want, but since you
asked:

''' START CODE '''
Private Declare Function SystemParametersInfo Lib "user32" _
Alias "SystemParametersInfoA" _
(ByVal uAction As Long, ByVal uParam As Long, _
lpvParam As Any, ByVal fuWinIni As Long) As Long
Private Const SPIF_SENDCHANGE = 1
Private Const SPI_SETKEYBOARDSPEED = 11
Private Const SPI_SETKEYBOARDDELAY = 23

Public Function SetKBspeed(NewSpeed As Long) As Boolean

'Pass a number between 0 and 31
'31 is the fastest speed
'0 is the slowest

Dim Retcode As Long
Dim dummy As Long

Retcode = SystemParametersInfo(SPI_SETKEYBOARDSPEED, _
NewSpeed, dummy, SPIF_SENDCHANGE)

SetKBspeed = (Retcode > 0)
End Function

Public Function SetKBdelay(NewDelay As Long) As Boolean

'Pass a value between 0 and 3. 0 for the shortest delay
'(about 250 ms) 3 for the longest about 1 sec)

Dim Retcode As Long
Dim dummy As Long

Retcode = SystemParametersInfo(SPI_SETKEYBOARDDELAY, _
NewDelay, dummy, SPIF_SENDCHANGE)

SetKBdelay = (Retcode > 0)
End Function
''' END CODE '''

Paste that code into a new standard module. Both functions return True if
successful, False otherwise.
 
R

rwboyden via AccessMonster.com

Stuart said:
Is there a means via VBA code to set the keyboard repeat rate (as is done
via
[quoted text clipped - 5 lines]
we scroll, then restore the default repeat rate in the Lost Focus event of
the list control.

There's more than one way to achieve the behaviour you want, but since you
asked:

''' START CODE '''
Private Declare Function SystemParametersInfo Lib "user32" _
Alias "SystemParametersInfoA" _
(ByVal uAction As Long, ByVal uParam As Long, _
lpvParam As Any, ByVal fuWinIni As Long) As Long
Private Const SPIF_SENDCHANGE = 1
Private Const SPI_SETKEYBOARDSPEED = 11
Private Const SPI_SETKEYBOARDDELAY = 23

Public Function SetKBspeed(NewSpeed As Long) As Boolean

'Pass a number between 0 and 31
'31 is the fastest speed
'0 is the slowest

Dim Retcode As Long
Dim dummy As Long

Retcode = SystemParametersInfo(SPI_SETKEYBOARDSPEED, _
NewSpeed, dummy, SPIF_SENDCHANGE)

SetKBspeed = (Retcode > 0)
End Function

Public Function SetKBdelay(NewDelay As Long) As Boolean

'Pass a value between 0 and 3. 0 for the shortest delay
'(about 250 ms) 3 for the longest about 1 sec)

Dim Retcode As Long
Dim dummy As Long

Retcode = SystemParametersInfo(SPI_SETKEYBOARDDELAY, _
NewDelay, dummy, SPIF_SENDCHANGE)

SetKBdelay = (Retcode > 0)
End Function
''' END CODE '''

Paste that code into a new standard module. Both functions return True if
successful, False otherwise.

THANKS ... It works perfectly!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top