|
-
Nov 13th, 2007, 05:19 AM
#1
[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.
-
Nov 13th, 2007, 06:49 AM
#2
Addicted Member
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
-
Nov 13th, 2007, 07:16 AM
#3
Re: KeyDown (loosing focus problem)
Where is the focus that you have to reset?
-
Nov 13th, 2007, 01:12 PM
#4
Re: KeyDown (loosing focus problem)
 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.
 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?
-
Nov 13th, 2007, 01:16 PM
#5
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?
-
Nov 14th, 2007, 03:52 AM
#6
Re: KeyDown (loosing focus problem)
 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
-
Nov 14th, 2007, 04:55 AM
#7
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 14th, 2007, 05:05 AM
#8
Re: KeyDown (loosing focus problem)
 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.
 Originally Posted by westconn1
or instead of setting it's value to true, just call its click event
I did - it's the same.
-
Nov 14th, 2007, 05:11 AM
#9
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"
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
|