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
Printable View
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
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
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)
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...
Not in this case. Because we are using the GetKeyState API, it will only trigger when both keys are pressed at the same time.
but gyus, back to my problem, thanks. How in general is it
possible to identify the control which triggered an event?
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.
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.
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