Results 1 to 9 of 9

Thread: [RESOLVED] [2005] Turn off Key Repeat Delay

  1. #1

    Thread Starter
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Resolved [RESOLVED] [2005] Turn off Key Repeat Delay

    I'm looking for a way to get rid of the delay when a user presses a key. The Key_Down event unfortunately is affected by this and I'm making a type of game that needs smooth movement.

    My current solution involves a timer and sort of my own makeshift way around it, it's almost perfect but quickly switching left and right keys gets buggy from the key repeat delay.

    In the 6.0 section I found these two topics:
    http://www.vbforums.com/showthread.p...y+repeat+delay
    http://www.vbforums.com/showthread.p...y+repeat+delay

    There both pretty much the same, It almost worked in VB.Net but when declaring "lpvParam As Any", the any part was marked as an unknown variable type. I guess that's something unique to 6.0.

    Does anyone know a way to do this in .NET?
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2005] Turn off Key Repeat Delay

    Do you really want to change the entires systems repeat value? That would affect all programs on the PC.

    Couldn't you listen for the KeyDown and KeyUp events and then just respond to the first keydown event and set a flag that the key is down and just do your action in a timer with a short interval? Then when the keyup is fired unset the flag.

  3. #3

    Thread Starter
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: [2005] Turn off Key Repeat Delay

    Quote Originally Posted by Negative0
    Do you really want to change the entires systems repeat value? That would affect all programs on the PC.
    Yes, according to the 6.0 version though it's not permanent unless you make the Boolean value "Permanent" equal to true.

    Couldn't you listen for the KeyDown and KeyUp events and then just respond to the first keydown event and set a flag that the key is down and just do your action in a timer with a short interval? Then when the keyup is fired unset the flag.
    As explained in the first post this is what I am currently doing but it's buggy and I want to know if there is a direct way to turn off the delay.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2005] Turn off Key Repeat Delay

    If you need the proper declaration for that API call, look at this entry on pinvoke:

    http://pinvoke.net/default.aspx/user...etersInfo.html

  5. #5

    Thread Starter
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: [2005] Turn off Key Repeat Delay

    According to that "any" should be type Integer. It only includes the declarations though, I can't find any other code to actually do anything, so I took the rest code from the 6.0 topics and when I called the function, nothing happened.

    Here's what I tried:
    Code:
        Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Integer, ByVal fuWinIni As Long) As Long
        Const SPI_SETKEYBOARDDELAY As Long = 23
        Const SPI_SETKEYBOARDSPEED As Long = 11
        Const SPIF_SENDWININICHANGE As Long = &H2
        Private Const SPIF_SENDCHANGE = 1
        Const SPIF_UPDATEINIFILE As Long = &H1
    
        Public Function SetKeyBoardDelay(ByVal NewDelay As Long) As Boolean
            'PASS A VALUE BETEEN 0 AND 3.  0 for the SHORTEST DELAY
            '(ABOUT 250 ms) 3 for the longset (ABOUT 1 sec)
    
            Dim Retcode As Long
            Dim dummy As Long
            dummy = 0
    
            Retcode = SystemParametersInfo(SPI_SETKEYBOARDDELAY, NewDelay, dummy, SPIF_SENDCHANGE)
    
            SetKeyBoardDelay = (Retcode > 0)
        End Function
    Any other ideas?
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  6. #6
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2005] Turn off Key Repeat Delay

    You need to change all of your longs to integers. In VB6 a Long was a 32 bit value, in .Net an integer is a 32 bit value.

  7. #7

    Thread Starter
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: [2005] Turn off Key Repeat Delay

    Quote Originally Posted by Negative0
    You need to change all of your longs to integers. In VB6 a Long was a 32 bit value, in .Net an integer is a 32 bit value.
    Ok thanks I'll try it and post back. I'm terrible with anything but the core VB.Net language so I'm lost in trying to get this API to work.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  8. #8

    Thread Starter
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: [2005] Turn off Key Repeat Delay

    Still doesn't work =(

    Code:
        Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer, ByVal lpvParam As Integer, ByVal fuWinIni As Integer) As Integer
        Const SPI_SETKEYBOARDDELAY As Integer = 23
        Const SPI_SETKEYBOARDSPEED As Integer = 11
        Const SPIF_SENDWININICHANGE As Integer = 2
        Const SPIF_UPDATEINIFILE As Integer = 1
    
        Sub SetKeyboardRepeatInfo(ByVal Delay As Integer)
            Dim flags As Integer
    
            ' set the keyboard delay
            SystemParametersInfo(SPI_SETKEYBOARDDELAY, Delay, 0, flags)
    
        End Sub
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  9. #9

    Thread Starter
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: [2005] Turn off Key Repeat Delay

    I finally found something that works, it was actually from Bulldog in an old help topic on detecting multiple keypresses.

    Declaration
    Code:
        Private Declare Function GetAsyncKeyState Lib "user32" (ByVal keyCode As Integer) As Integer
    And originally it was using If GetAsyncKeyState(Keys.KEY) as a boolean but that still had delay, however if you use

    Code:
    If GetAsyncKeyState(Keys.KEY) < 0 Then...
    along with a timer to check it every millisecond, it will work around the key repeat delay. The other way was much like this however when switching from left to right quickly the form would not always pick the keypress up and the moves would cancel out, with GetAsynKeyState the transition is smooth and flawless.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

Tags for this Thread

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