|
-
Aug 2nd, 2010, 11:33 AM
#1
Thread Starter
Member
Turning a Boolean FALSE if the right KeyData isn't pressed.
Hey! Me again! A week or so ago, you folks really taught me how to use the KeyData event. I adopted some of the coding to make my new code so much better. A few days ago, I thought I figured out how to run my little game. You see, you have two buttons. Comment and Uncomment. You Press Control + K and then after that, you press Control + (C or U) to activate the buttons. And I thought it worked! But my buddy figured out how to break it! The thing is, I need to figure out a way to make IsCtrlK (Look below) False if any key that isn't Control + C or U is pressed right after it. What would you suggest I look into using?
Here is the code.
Code:
Dim IsCtrlK As Boolean
Select Case e.KeyData
Case Keys.Control Or Keys.K
IsCtrlK = True
End Select
If IsCtrlK = True Then
Select Case e.KeyData
Case Keys.Control Or Keys.C
ToolstripButtonCommentText.PerformClick()
IsCtrlK = False
Case Keys.Control Or Keys.U
ToolstripButtonUncommentText.PerformClick()
IsCtrlK = False
End Select
End If
Last edited by kleinma; Aug 2nd, 2010 at 12:33 PM.
Reason: formatted code
-
Aug 2nd, 2010, 11:46 AM
#2
Re: Turning a Boolean FALSE if the right KeyData isn't pressed.
Could you wrap the code in a code block? It's really hard to read & understand like that.
In short, you'll want to check for just the ctrl key (and if so) then check for K, C or U inside the If block.
-
Aug 2nd, 2010, 12:52 PM
#3
Thread Starter
Member
Re: Turning a Boolean FALSE if the right KeyData isn't pressed.
Ah- Sorry about that.
What I'm wanting to do is press Control + K and then having to press Control + (C or U) to activate the button click event. The problem is, with the current code, if I press Control + K and then... A bunch of other keys... and THEN Control + (C or U), it still counts. I want it to be Control + K then Control + (C or U) or no dice. If another key is pressed before the Control + (C or U), then I want to it not to count as the correct combination.
-
Aug 2nd, 2010, 01:13 PM
#4
Re: Turning a Boolean FALSE if the right KeyData isn't pressed.
how about something like this?
Code:
Static IsCtrlK As Boolean
'IF CTRL+K HAS NOT BEEN PRESSED YET, CHECK FOR IT SINCE IT
'IS THE FIRST THING THAT NEEDS TO HAPPEN
If Not IsCtrlK Then
IsCtrlK = (Keys.Control Or Keys.K) = e.KeyData
Else
'SINCE CTRL+K WAS PREVIOUSLT PRESSED
'IT SHOULD BE SET TO FALSE NOW UNDER ALL SCENARIOS
IsCtrlK = False
'CHECK FOR CTRL+C OR CTRL+U
Select Case e.KeyData
Case Keys.Control Or Keys.C
ToolstripButtonCommentText.PerformClick()
Case Keys.Control Or Keys.U
ToolstripButtonUncommentText.PerformClick()
End Select
End If
-
Aug 2nd, 2010, 10:18 PM
#5
Re: Turning a Boolean FALSE if the right KeyData isn't pressed.
Here's my take:
vb.net Code:
Static isInCtrlKChord As Boolean = False Select Case e.KeyData Case Keys.Control Or Keys.K isInCtrlKChord = Not isInCtrlKChord Case Keys.Control Or Keys.C 'Do whatever. isInCtrlKChord = False Case Keys.Control Or Keys.U 'Do whatever. isInCtrlKChord = False Case Else isInCtrlKChord = False End Select
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
|