|
-
Feb 26th, 2006, 12:08 AM
#1
Thread Starter
Member
[RESOLVED] Invisible Menu Hotkeys
Is there a way to have hotkeys for a menu that's not visible? I tried but they don't work for some reason
-
Feb 26th, 2006, 12:16 AM
#2
Re: Invisible Menu Hotkeys
I don't think there is a way to do it using the menu editor but you can do it through code.
VB Code:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If Shift = vbCtrlMask And KeyCode = vbKeyA Then
mnuItem_Click
End If
End Sub
Private Sub Form_Load()
Me.KeyPreview = True
End Sub
Private Sub mnuItem_Click()
MsgBox "Click"
End Sub
-
Feb 26th, 2006, 12:24 AM
#3
Thread Starter
Member
Re: Invisible Menu Hotkeys
What if I'm using a MDI Form (No _KeyUp event) :-\
-
Feb 26th, 2006, 12:29 AM
#4
Re: Invisible Menu Hotkeys
 Originally Posted by Mephy
What if I'm using a MDI Form (No _KeyUp event) :-\
In that case maybe you could use GetAsyncKeyState API with a Timer.
-
Feb 26th, 2006, 12:33 AM
#5
Re: Invisible Menu Hotkeys
Well i can think of two ways, one is to set a system wide hotkey and use that (except if the program doesn't have focus, and you press the keys it will still 'click' the menu), and the other is to add the code to all the mdichild windows and make it 'click' the menu on the MDI Form.
-
Feb 26th, 2006, 01:14 AM
#6
Thread Starter
Member
Re: Invisible Menu Hotkeys
I added the following code to a MDI Child and nothing happened.
VB Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
MsgBox KeyCode
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
MsgBox KeyAscii
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
MsgBox KeyCode
End Sub
-
Feb 26th, 2006, 05:13 AM
#7
Re: Invisible Menu Hotkeys
You must have Keypreview property set to true (of the form) for the form to get the keys pressed.
-
Feb 26th, 2006, 11:36 AM
#8
Thread Starter
Member
Re: Invisible Menu Hotkeys
Alright, I can get when a key is pressed now, but I'm having trouble calling a Sub. I have the sub Menu1_Click(Index as integer) in frmMain. and i'm trying to call it from Form2
-
Feb 27th, 2006, 10:06 PM
#9
Thread Starter
Member
Re: Invisible Menu Hotkeys
Not sure if your allowed to bump posts but this one's about to get deleted and i still need a little help
-
Feb 27th, 2006, 10:25 PM
#10
Re: Invisible Menu Hotkeys
Remove the code you have inside that invisible menu Click Event, and add it to a Sub, you can still call that sub in the menu click event if you want.
Now that the code is in a sub you can execute it with keys, this will execute with Control-A:
Add a TIMER control to your MDI Form.
VB Code:
Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" _
(ByVal vKey As Long) As Integer
Private Sub ExecuteSomething() 'Now the code is in this sub
MsgBox "Ok!"
End Sub
Private Sub MDIForm_Load()
Timer1.Interval = 1
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
If CBool(GetAsyncKeyState(vbKeyControl)) And CBool(GetAsyncKeyState(vbKeyA)) Then
ExecuteSomething
End If
End Sub
-
Feb 28th, 2006, 07:59 AM
#11
Re: Invisible Menu Hotkeys
jcis, the only problem with that is that if any other program has focus, and the keys are pressed then it will still run the sub.
Either way here is a way to call the sub
VB Code:
'In form1
'Removed the Private Sub ... and left it as Sub.... only
Sub mnuitem_Click()
MsgBox "Click"
End Sub
'In form2
Private Sub Command1_Click()
Call Form1.mnuitem_Click
End Sub
-
Feb 28th, 2006, 08:06 AM
#12
Re: Invisible Menu Hotkeys
 Originally Posted by Andrew G
jcis, the only problem with that is that if any other program has focus, and the keys are pressed then it will still run the sub.
Either way here is a way to call the sub
VB Code:
'In form1
'Removed the Private Sub ... and left it as Sub.... only
Sub mnuitem_Click()
MsgBox "Click"
End Sub
'In form2
Private Sub Command1_Click()
Call Form1.mnuitem_Click
End Sub
Ok, but, why that code uses 2 Forms? shouldn't all happend inside the MDI Form? Or in MDI Form the focus is always on a child? I'm not sure cause I never used MDI.
-
Feb 28th, 2006, 08:15 AM
#13
Re: Invisible Menu Hotkeys
oops. Sorry by Form2 i meant the mdi child and form1 is the MDI form
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
|