|
-
Aug 6th, 2000, 12:03 PM
#1
Thread Starter
Lively Member
Ok, this one is the last question for today! ;-)
I would like the enter key to call a sub ("uguale"). I put
the following code in the Form_KeyPress Sub:
If KeyAscii = 13 Then
uguale_Click
KeyAscii = 0
End If
The problem is that if i click a button of the form and then
i press Enter, it does no more call "uguale", but simulates
a click on the button (that got the focus); i have this
problem only with keyascii 13. Is there a way to make Enter
call always "uguale" also if the focus is on a button or something else, without using a keypress event for each button? There are about 60 buttons... would be a little tedious! ;-)
Thankyou
-
Aug 6th, 2000, 12:36 PM
#2
Monday Morning Lunatic
I assume this follows on from your other thread . There isn't really a way to catch the event for them all, without subclassing. Although I expect Megatron will work something out .
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 6th, 2000, 01:47 PM
#3
Try the GetAsyncKeyState API. Make a Form with a Timer and set it's Interval to 1.
Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Sub Timer1_Timer()
If GetForegroundWindow = Me.hWnd Then If GetAsyncKeyState(vbKeyReturn) = &H8000 Then Call uguale_Click
End Sub
[Edited by Megatron on 08-06-2000 at 02:53 PM]
-
Aug 6th, 2000, 02:14 PM
#4
Monday Morning Lunatic
Aha. Polling the keyboard - didn't think of that. One thought, though. Won't it slow down your program a bit? The odd keypress may be missed at the rather abysmal rate the VB timer moves at.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 6th, 2000, 02:44 PM
#5
Yes, it can produce some rather unpredictable results, but for the most part, it can capture the EnterKey and that's basically what we are concerned about here.
-
Aug 6th, 2000, 02:58 PM
#6
I see your point regarding the speed if the Timer's interval was 500 or so. If you set it to 1 (or even 100), it will capture the keys as if you were typing in a TextBox. This API can make a great Spy application for shared computer's, i.e: if someone is writing a private E-mail, your program can capture the keys that were pressed and log them to a file.
-
Aug 6th, 2000, 03:40 PM
#7
Thread Starter
Lively Member
Well... i feel really like a newbie! ;-) Wow, that's
fantastic...
Eheh! Thanks a lot Megatron and parksie!
-
Aug 6th, 2000, 03:57 PM
#8
Thread Starter
Lively Member
Hi!
Ok, i've tried the keyboard polling solution but there
are some problems:
1. Sometimes pressing Enter works well: does not press
the button and calls "uguale"
2. Sometimes it presses the button with focus and then
calls "uguale"
3. Sometimes it presses the button with focus and nothing
else
So i'm getting crazy with that! ;-) Do you imagine another
solution? Is there a way to make buttons not to get focus
state (or maybe, to pass focus state to the textfield as
they're relased?)?
If you have no other ideas, well! I'm gonna change each
button's code... Eheh! Thanks a lot... do not get crazy with
this...
Thanx
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
|