News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

How to set the new keyboard TYPEMATIC RATE/DELAY ?

Started by elmo, March 28, 2011, 06:09:45 AM

Previous topic - Next topic

elmo

I try to modify code from
http://www.freewebs.com/four-f/index.htm
especially file   
KmdKit.zip\KmdKit\examples\nodriver\KbdTypematic

I can get the current value of KEYBOARD TYPEMATIC RATE/DELAY, but
when I want to set the new value of KEYBOARD TYPEMATIC RATE/DELAY, the following code always show me this message:
  "Couldn't set keyboard typematic parameters"
so, I think it's wrong code.

Would you like to help me in this part? What's wrong with the following code?
thank you.
sorry for my bad english.

;SET THE NEW KEYBOARD TYPEMATIC RATE/DELAY
and ebx,FALSE ;assume error
mov eax,dwKBDUnitId
mov ktp.UnitId,ax

;Typematic rate, in repeats per second.
invoke SendMessage,hTrack1,TBM_GETPOS,0,0
mov ecx,dwKBDMaxRate
sub ecx,dwKBDMinRate
shr ecx,4 ;/16
xor edx,edx
mul ecx
add eax,dwKBDMinRate
mov ktp.Rate,ax


;Typematic delay, in milliseconds.
invoke SendMessage,hTrack2,TBM_GETPOS,0,0
mov ecx,dwKBDMaxDelay
sub ecx,dwKBDMinDelay
shr ecx,3 ;/8
xor edx,edx
mul ecx
add eax,dwKBDMinDelay
mov ktp.Delay,ax
invoke DeviceIoControl,
hKBDdevice,
IOCTL_KEYBOARD_SET_TYPEMATIC,
addr ktp,
sizeof ktp,
NULL,
0,
addr dwBytesReturned,
NULL
.if (eax!=0)
mov ebx,TRUE ;indicate success
.endif
mov eax,ebx
.if eax == TRUE
.else
invoke MessageBox,NULL,SADD("Couldn't set keyboard typematic parameters"),NULL, MB_ICONEXCLAMATION
.endif

be the king of accounting programmer world!

dedndave

the SystemParametersInfo function may be used to get/set the delay and/or rate:

        INVOKE  SystemParametersInfo,uiAction,uiParam,pvParam,fWinIni

uiAction, uiParam, pvParam:
SPI_GETKEYBOARDDELAY, pvParam points to a dword value
SPI_GETKEYBOARDSPEED, pvParam points to a dword value
SPI_SETKEYBOARDDELAY, uiParam = 0, 1, 2, 3 - 0 sets the shortest delay (~250 ms), 3 sets the longest delay (~1 second)
SPI_SETKEYBOARDSPEED, uiParam = 0 to 31 - 0 (~2.5 repetitions per second) - 31 (~30 repetitions per second)
for the GET functions, uiParam = NULL, for the SET functions, pvParam = NULL

fWinIni may be any combinataion of the following, or NULL:
SPIF_SENDCHANGE, broadcast WM_SETTINGCHANGE to all windows
SPIF_UPDATEINIFILE, update user profile

i do not recommend updating the user profile without user consent
i would be upset if a program did that to me   :P

dedndave

as i recall, this function is not supported on Win95
;###############################################################

        .DATA?

        ALIGN   4

kbDelay dd ?
kbRate  dd ?

;###############################################################

        .CODE

_main   PROC

;get keyboard delay

        INVOKE  SystemParametersInfo,SPI_GETKEYBOARDDELAY,NULL,offset kbDelay,NULL

;get keyboard repeat rate

        INVOKE  SystemParametersInfo,SPI_GETKEYBOARDSPEED,NULL,offset kbRate,NULL

;set keyboard delay

        INVOKE  SystemParametersInfo,SPI_SETKEYBOARDDELAY,kbDelay,NULL,NULL

;set keyboard repeat rate

        INVOKE  SystemParametersInfo,SPI_SETKEYBOARDSPEED,kbRate,NULL,NULL

;exit

        INVOKE  ExitProcess,NULL

_main   ENDP

;###############################################################

elmo

wow, i wonder how do you know that?

yes, i found in internet we can also swap mouse button with SystemParametersInfo with this:
      invoke SystemParametersInfo, SPI_SETMOUSEBUTTONSWAP, 1, NULL, NULL          ;SWAP
      invoke SystemParametersInfo, SPI_SETMOUSEBUTTONSWAP, 0, NULL, NULL         ;DEFAULT
be the king of accounting programmer world!

dedndave