The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: elmo on March 28, 2011, 06:09:45 AM

Title: How to set the new keyboard TYPEMATIC RATE/DELAY ?
Post by: elmo on March 28, 2011, 06:09:45 AM
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

Title: Re: How to set the new keyboard TYPEMATIC RATE/DELAY ?
Post by: dedndave on March 28, 2011, 12:27:24 PM
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
Title: Re: How to set the new keyboard TYPEMATIC RATE/DELAY ?
Post by: dedndave on March 28, 2011, 01:51:46 PM
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

;###############################################################
Title: Re: How to set the new keyboard TYPEMATIC RATE/DELAY ?
Post by: elmo on March 29, 2011, 07:32:13 AM
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
Title: Re: How to set the new keyboard TYPEMATIC RATE/DELAY ?
Post by: dedndave on March 29, 2011, 09:10:47 AM
that function will do a lot of stuff   :bg
http://msdn.microsoft.com/en-us/library/ms724947%28v=VS.85%29.aspx

it is simpler to use GetSystemMetrics for some things, and it is supported on Win95
http://msdn.microsoft.com/en-us/library/ms724385%28v=VS.85%29.aspx