|
-
Aug 18th, 2004, 04:07 PM
#1
Thread Starter
Junior Member
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
-
Aug 18th, 2004, 04:26 PM
#2
Try This:
VB Code:
' #VBIDEUtils#*****************************************
' * Programmer Name : Waty Thierry
' * Web Site : [url]http://www.geocities.com/ResearchTriangle/6311/[/url]
' * Date : 25/11/1999
' * Time : 15:59
' *************************************************************
' * Comments : Change the keyboard speed and the repeat delay
' *
' ********************************************************
Private Declare Function SystemParametersInfo Lib "user32" _
Alias "SystemParametersInfoA" (ByVal uAction As Long, _
ByVal uParam As Long, ByVal lpvParam As Any, _
ByVal fuWinIni As Long) As Long
Private Const SPI_SETKEYBOARDDELAY = 23
Private Const SPI_SETKEYBOARDSPEED = 11
Private Const SPIF_SENDCHANGE = 1
And:
VB Code:
Public Function SetKeyBoardSpeed(NewSpeed As Long) As Boolean
'PASS A NUMBER BETWEEN 0 AND 31
'31 IS THE FASTEST SPEED
'0 IS THE SLOWEST
Dim Retcode As Long
Dim dummy As Long
Retcode = SystemParametersInfo(SPI_SETKEYBOARDSPEED, _
NewSpeed, dummy, SPIF_SENDCHANGE)
SetKeyBoardSpeed = (Retcode > 0)
End Function
Public Function SetKeyBoardDelay(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, SPIIF_SENDCHANGE)
SetKeyBoardDelay = (Retcode > 0)
End Function
Found here:
http://www.freevbcode.com/ShowCode.asp?ID=511
-
Aug 19th, 2004, 09:19 AM
#3
Thread Starter
Junior Member
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
-
Aug 19th, 2004, 09:25 AM
#4
<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.
-
Aug 19th, 2004, 01:12 PM
#5
Thread Starter
Junior Member
<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
-
Aug 19th, 2004, 01:25 PM
#6
<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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|