Results 1 to 6 of 6

Thread: keyboard repeat delay, can this be set by VB to 0?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2004
    Posts
    19

    keyboard repeat delay, can this be set by VB to 0?

    Hi All,

    I am using the Form_Keypress function to capture keystrokes and send them out via the serial port. I want to set the repeat delay to 0. You know how when typing in a word processor program when you hold a key down, the character appears on the screen, there is a short delay, then the charcter begins to repeat across the screen. Using the control panel of the computer, I can set it pretty low, but I want no delay at all.

    What I am doing is controlling a robot with the keyboard, so the initial repeat delay causes a stutter in the robot's motion. If there was no repeat delay, no stutter. I've looked, but I can't see a way to set that.

    Thanks,

    Jonathan

    www.madlabs.info

  2. #2
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961
    Try This:

    VB Code:
    1. ' #VBIDEUtils#*****************************************
    2. ' * Programmer Name  : Waty Thierry
    3. ' * Web Site   : [url]http://www.geocities.com/ResearchTriangle/6311/[/url]
    4. ' * E-Mail     : [email][email protected][/email]
    5. ' * Date       : 25/11/1999
    6. ' * Time       : 15:59
    7. ' *************************************************************
    8. ' * Comments   : Change the keyboard speed and the repeat delay
    9. ' *
    10. ' ********************************************************
    11. Private Declare Function SystemParametersInfo Lib "user32" _
    12.   Alias "SystemParametersInfoA" (ByVal uAction As Long, _
    13.    ByVal uParam As Long, ByVal lpvParam As Any, _
    14.    ByVal fuWinIni As Long) As Long
    15.  
    16. Private Const SPI_SETKEYBOARDDELAY = 23
    17. Private Const SPI_SETKEYBOARDSPEED = 11
    18. Private Const SPIF_SENDCHANGE = 1


    And:

    VB Code:
    1. Public Function SetKeyBoardSpeed(NewSpeed As Long) As Boolean
    2.  
    3. 'PASS A NUMBER BETWEEN 0 AND 31
    4. '31 IS THE FASTEST SPEED
    5. '0 IS THE SLOWEST
    6.  
    7.    Dim Retcode As Long
    8.    Dim dummy As Long
    9.  
    10.    Retcode = SystemParametersInfo(SPI_SETKEYBOARDSPEED, _
    11.       NewSpeed, dummy, SPIF_SENDCHANGE)
    12.  
    13.   SetKeyBoardSpeed = (Retcode > 0)
    14. End Function
    15.  
    16. Public Function SetKeyBoardDelay(NewDelay As Long) As Boolean
    17. 'PASS A VALUE BETEEN 0 AND 3.  0 for the SHORTEST DELAY
    18. '(ABOUT 250 ms) 3 for the longset (ABOUT 1 sec)
    19.  
    20.    Dim Retcode As Long
    21.    Dim dummy As Long
    22.    dummy = 0
    23.    
    24.      Retcode = SystemParametersInfo(SPI_SETKEYBOARDDELAY, _
    25.          NewDelay, dummy, SPIIF_SENDCHANGE)
    26.  
    27.       SetKeyBoardDelay = (Retcode > 0)
    28. End Function

    Found here:

    http://www.freevbcode.com/ShowCode.asp?ID=511

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2004
    Posts
    19
    Dave,

    Thanks! I'm having a little trouble getting it to work, but I'm sure I can. My question is, is 250mS any faster than can be set by the computer's control panel? At a guess, I'd say no. Have any idea if that is true?

    Thanks again,

    Jonathan

    www.madlabs.info

  4. #4
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961
    <Star Trek>

    Sorry Captain, that's as much as I can give yer! She'll buckle if we take 'er any faster!

    </Star Trek>

    Basically those are IEEE standard settings that cannot be changed.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2004
    Posts
    19
    <Star Trek>

    Scotty, divert everything but life support to the warp drive! I *MUST* have more power!

    But Sir!! I dinna know how much longer she'll take! The dilithium cyrstals are going to blow!

    </ Star Trek>

    Dang. Guess what I will have to do is somehow intercept the keystroke and do some sort of loop to send out the commands. There has to be a way around this. I will break the 250mS barrier!

    Thanks for all the help, dave

    Jonathan

    www.madlabs.info

  6. #6
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961
    <Star Trek>

    Sir! Ye moost be crazy to think ye cun take 'er to sooch extremes!! I cannot keep 'er together mooch longer!!! Take a step back from yer captain's chair and think about what yer doin!

    </Star Trek>

    Yes, it is time to "refactor" your program. I am assuming you sent a command everytime the key_Press event was fired, which you can only get to occur every 250 ms.

    I wrote a keyboard handler once in assembly, but I think you can do it in VB also.

    If you want to try something new:

    - In the KeyDown event, set some global variable to represent the command you want to send.

    - Have a timer object fire at maximum frequency (adjustable)

    - Every time the timer event gets fired, check and send the command matching the global variable that was set in the KeyDown event

    - *important* in the KeyUP event, RESET the global command to not send any commands

    Let me know how that works if you try it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width