[RESOLVED] KeyDown (loosing focus problem)
I have a CommandButton which executes some code (shows a Form modally). I'm using a "shortcut" for it - F10 - and .KeyPreview at True:
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case (KeyCode)
Case vbKeyF2
'...
Case vbKeyF10
cmdUsers.Value = True
Case vbKeyF12
'...
End Select
End Sub
But whenever i press F10 and it doesn't get executed (for some reason that is not important), i have to re-set focus to any other control (even thow cmdUsers is NOT visible) in order for any other "shortcut" (F2, F12) to work. Why's that? It work's fine after when the code executes normally.
Re: KeyDown (loosing focus problem)
1. The sample code as given works fine.
2. Please ensure that F10 key is not set as shortcut to anyother Desktop application
3. Also kindly correct the code as :
Code:
Case vbKeyF10
cmdUsers.Value = True
cmdUsers.SetFocus
Re: KeyDown (loosing focus problem)
Where is the focus that you have to reset?
Re: KeyDown (loosing focus problem)
Quote:
Originally Posted by cheenu_vasan
1. The sample code as given works fine.
2. Please ensure that F10 key is not set as shortcut to anyother Desktop application
3. Also kindly correct the code as :
Code:
Case vbKeyF10
cmdUsers.Value = True
cmdUsers.SetFocus
1. Well... i already explained when it works - perhaps you should re-"read" my post :)
2. I did. It's not being used.
3. I cannot set the focus, because sometimes the cmdUsers isn't visible.
Quote:
Originally Posted by Hack
Where is the focus that you have to reset?
It doesn't matter. It's actually on a ListView. But, for some reason, i simply have to click somewhere (ANYWHERE!!) in order for "shortcuts" to work. It's very very strange. On the other hand, it F10 executes it's code, "shortcuts" work fine. Should i "flush" the keyboard, perhaps? Like "fflush()" in C? If so, how is it being done in VB?
Re: KeyDown (loosing focus problem)
Well, as odd as it may sound, it the focus is on a ListView, why not use its KeyDown event?
Re: KeyDown (loosing focus problem)
Quote:
Originally Posted by Hack
Well, as odd as it may sound, it the focus is on a ListView, why not use its KeyDown event?
True. But the focus can be ANYWHERE ELSE as well :)
Re: KeyDown (loosing focus problem)
maybe if the control is not visible you just need to setfocus to some visible control
or instead of setting it's value to true, just call its click event
Re: KeyDown (loosing focus problem)
Quote:
Originally Posted by westconn1
maybe if the control is not visible you just need to setfocus to some visible control
I tried using Me.ActiveControl.SetFocus - but nothing happens. I still gotta click somewhere in order for "shortcuts" to work again.
Quote:
Originally Posted by westconn1
or instead of setting it's value to true, just call its click event
I did - it's the same.
Re: KeyDown (loosing focus problem)
Well. I guess it's being used by another application. But nothing happens when i press it - but for some reason, it "freezes" my application. I'll use another "shortcut" :)