-
Mar 4th, 2009, 09:05 PM
#1
Thread Starter
Fanatic Member
[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?
-
Mar 4th, 2009, 09:34 PM
#2
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.
-
Mar 4th, 2009, 09:38 PM
#3
Thread Starter
Fanatic Member
Re: [2005] Turn off Key Repeat Delay
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.
-
Mar 4th, 2009, 09:41 PM
#4
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
-
Mar 4th, 2009, 11:02 PM
#5
Thread Starter
Fanatic Member
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?
-
Mar 5th, 2009, 07:43 AM
#6
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.
-
Mar 5th, 2009, 05:17 PM
#7
Thread Starter
Fanatic Member
Re: [2005] Turn off Key Repeat Delay
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.
-
Mar 5th, 2009, 07:37 PM
#8
Thread Starter
Fanatic Member
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
-
May 20th, 2009, 09:26 PM
#9
Thread Starter
Fanatic Member
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.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|