|
-
Jul 28th, 2000, 05:01 PM
#1
Thread Starter
New Member
I have a lot textboxes in my app. Since I don't like to
check in each if CTRL C was pressed, is there a solution
for this?
How can I check on CTRL C, maybe in general without
orientation to a control?
thanks
37.5% of all statistics are made up
on the spot
-
Jul 28th, 2000, 05:35 PM
#2
You can make an Array of TextBoxes and use the GetKeyState API to determine if they were pressed.
Code:
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Sub Text1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
'If Control and C are pressed then
If GetKeyState(vbKeyControl) And GetKeyState(vbKeyC) Then
MsgBox ("Control + C was pressed")
End If
End Sub
-
Jul 28th, 2000, 05:38 PM
#3
Thread Starter
New Member
My problem would be more like how can I find out in which
textbox CTRL C was pressed ?
(since I have a shortcut defined for the menu entry 'Copy'
it is easy to handle this)
37.5% of all statistics are made up
on the spot
-
Jul 28th, 2000, 05:47 PM
#4
Fanatic Member
Megatron,
Not to question a Guru but wouldn't that code be better in a KeyUp event? Just in case the user is a little slow with the keys. For example, if they hit the Ctrl key first, hold it down, then press C? That event would fire for the Ctrl key before the user got to press the C.
Just curious...
-
Jul 28th, 2000, 05:55 PM
#5
Not in this case. Because we are using the GetKeyState API, it will only trigger when both keys are pressed at the same time.
-
Jul 28th, 2000, 06:00 PM
#6
Thread Starter
New Member
but gyus, back to my problem, thanks. How in general is it
possible to identify the control which triggered an event?
37.5% of all statistics are made up
on the spot
-
Jul 28th, 2000, 06:01 PM
#7
Fanatic Member
Thank you. I'm still reading Appleman's API book, I just finished with chapter 2. So the API is still a foreign language to me.
-
Jul 28th, 2000, 06:04 PM
#8
Fanatic Member
How about using a public variable and set it to the index value inside the procedure Megatron just posted. This way you can check this variable to see which textbox it was.
-
Jul 29th, 2000, 11:22 AM
#9
Try this.
Code:
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Sub Text1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
'If Control and C are pressed then
If GetKeyState(vbKeyControl) And GetKeyState(vbKeyC) Then
MsgBox ("Control + C was pressed in Text1(" & Index & ")")
End If
End Sub
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
|