Hello.
I have two active forms in my app, the Main one and another one. I would like to have the program transmit the keypresses from the other form to the Main one when it (the other form) is active.
Say, in the Main form, F3 triggers a specific event. I would like to have the Main form know that F3 has been pressed when it has no focus (when focus is on the other form).
Sendkeys COULD work, but for special keys (such as Enter) there would be trouble... (have to associate for example 13 to {ENTER})
Hello.
I have two active forms in my app, the Main one and another one. I would like to have the program transmit the keypresses from the other form to the Main one when it (the other form) is active.
Say, in the Main form, F3 triggers a specific event. I would like to have the Main form know that F3 has been pressed when it has no focus (when focus is on the other form).
Sendkeys COULD work, but for special keys (such as Enter) there would be trouble... (have to associate for example 13 to {ENTER})
In your other form, set the KeyPreview property to true. Then add a call in the KeyPress of your other form to inform the Main form which key was pressed.
Emiliano F. Martín
If a post has helped you then pleaseRate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
Ohh... hum... i feared that answer.
Actually, I thought about that...
But the keys are actually associated to Menus (in the Menu Editor), and not by stuff in the KeyPress Sub of the Main form...
It wouldn't work then, would it?
This works!! Set the timer's interval to 100 or so.
VB Code:
Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub submnuOpen_Click()
MsgBox "Open Clicked!!"
End Sub
Private Sub tmrKeyPress_Timer()
If GetAsyncKeyState(vbKeyF3) <> 0 Then
MsgBox "F3 was pressed!!"
End If
End Sub
Emiliano F. Martín
If a post has helped you then pleaseRate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
HUm... yes... but isn't there a way to do that without having to detect each key individually?
Like automatically sending the same keycode to the Main form?
HUm... yes... but isn't there a way to do that without having to detect each key individually?
Like automatically sending the same keycode to the Main form?
Have a look at the attach.
Emiliano F. Martín
If a post has helped you then pleaseRate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
Hum.... Actually, the menu is supposed to be on the Main form...
It won't work... I switched the menu to the main form, but now the only event that is triggered is the KeyPress, and not the menu click.....
Triggering the KeyPress event just won't work for me...
Hum.... Actually, the menu is supposed to be on the Main form...
It won't work... I switched the menu to the main form, but now the only event that is triggered is the KeyPress, and not the menu click.....
Triggering the KeyPress event just won't work for me...
I know this is not what you might be looking for... This goes into your Main.frm:
VB Code:
Option Explicit
Private Sub submnuOpen_Click()
MsgBox "Open Clicked!!"
End Sub
Public Sub Form_KeyPress(KeyAscii As Integer)
Text1.Text = KeyAscii
If KeyAscii = vbKeyF3 Then
' MsgBox "F3 was pressed!!"
submnuOpen_Click
End If
End Sub
Private Sub Form_Load()
Form1.Show
End Sub
If this is not what you want, you might explain better what you need. There might be another work-around.
Emiliano F. Martín
If a post has helped you then pleaseRate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
Yeah.... I didn't want to have to add that code for every menu item...
Well, if there is no other way, I guess I'll have to do that then...
Thanks for the help.
There may be a complexity that I am not seeing ?, but re -
Say, in the Main form, F3 triggers a specific event. I would like to have the Main form know that F3 has been pressed when it has no focus (when focus is on the other form).
Can't you just have a public property in the Main form.
And within that property you take certain actions depening on what was sent to that property.
Thus when F3 is pressed in the other form, it sends that info to the Main form's public property.