Keyboard typematic

gerotica
gerotica used Ask the Experts™
on
Hey
I need to set the keyboard typematic and delay in win2k using delphi. I tried to use SystemParametersInfo() and worked fine. But, i need to set these parameters together, because I need the whole byte (because typematic are bits 0 to 4 and delay are bits 5 and 6). SystemParametersInfo() sets them apart. Can anyon help me?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Engineer, Advisory
Top Expert 2005
Commented:

Given what your asking, you should have a function to create a byte value from the 2 inputs, and a function(s) to extract the repeat and delay from the byte value.

// Make a single byte value for repeat and delay
function MakeRepeatDelay(uRepeat, uDelay: Byte): Byte;
begin

  // Keep repeat in range from 0..31
  uRepeat:=uRepeat mod 32;

  // Keep delay in range from 0..3
  uDelay:=uDelay mod 4;

  // Set the repeat
  result:=uRepeat;

  // Calc the delay bits into the byte
  Inc(result, uDelay shl 5);

end;

// Get repeat from repeat and delay byte
function GetRepeat(uRepeatDelay: Byte): Byte;
begin

  // Get the repeat count from the RepeatDelay byte
  result:=uRepeatDelay mod 32;

end;

// Get delay from repeat and delay byte
function GetDelay(uRepeatDelay: Byte): Byte;
begin

  // Get the delay count from the RepeatDelay byte
  result:=uRepeatDelay shr 5;

end;

// Set the repeat and delay using a single byte value
function SetRepeatDelay(uRepeatDelay: Byte): Boolean;
begin

  result:=SystemParametersInfo(SPI_SETKEYBOARDSPEED, GetRepeat(uRepeatDelay), nil, SPIF_SENDCHANGE) and
          SystemParametersInfo(SPI_SETKEYBOARDDELAY, GetDelay(uRepeatDelay), nil, SPIF_SENDCHANGE);

end;

// Procedure to test all 4 functions
procedure TForm1.Button1Click(Sender: TObject);
var  repeatanddelay:   Byte;
begin

  // Given the following example
  repeatanddelay:=MakeRepeatDelay(20, 2);

  if GetRepeat(repeatanddelay) = 20 then
     beep;

  if GetDelay(repeatanddelay) = 2 then
     beep;

  if SetRepeatDelay(repeatanddelay) then
     beep;

end;

-----

Hope this was what you were looking for,
Russell



Author

Commented:
Im sorry, i didn´t explain correctly. I need a function that send both values together. If I want to set delay 2 and typematic 3 I have to send a simple 00100011

Author

Commented:
Its not a mathematic problem, its a communication problem
Russell LibbySoftware Engineer, Advisory
Top Expert 2005

Commented:

Sorry,

I guess I don't undestand your requirement to set both system values at the same time (I'm not sure you can either).

Is there an issue with calling SystemParametersInfo() twice (back to back)? Or are you having issues with the message broadcast of the change after each setting?

Russell

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial