zoldy
09-13-2000, 02:56 PM
I am using the forms keydown event to do the following
If KeyCode = 112 Then
cmdF1 = True
End If
So that when the F1 key is pressed the cmdf1 code executes
The problem is that it executes twice and I don't know why
If I press the command button it works fine
:) ZOLDY :)
SeiferTim
09-13-2000, 03:54 PM
Hmm... I was having a very similar problem on one of my programs but with "SendKeys"... I wish I knew... instead, try putting your cmdF1 proccedure in a Sub, and call it from both the button, and the key... that might help.
-Seifer Tim
Visit my Web-Site: http://solenoid.50megs.com
zoldy
09-13-2000, 03:58 PM
hmmmm... does the same thing but thanks for the suggestion
:) ZOLDY :)
SeiferTim
09-13-2000, 04:14 PM
What about using KeyPress instead of KeyDown... that may be your problem...
Visit my Web-Site: http://solenoid.50megs.com
zoldy
09-13-2000, 05:03 PM
hmmmm... doesn't work at all with the keypress event ??
:) ZOLDY :)
SeiferTim
09-13-2000, 05:12 PM
You know why? Did you change your VAriable in KeyPress? I believe it uses "KeyAscii" instead of "KeyCode"...
And I'm not sure if the values are the same for KeyCode and KeyAscii...
Visit my Web-Site: http://solenoid.50megs.com
Sparkey
09-13-2000, 11:52 PM
As I said in another post Zoldy, what is cmdF1? Is it a button with code behind the click event? Does the user hit the F1 key and then click the button?
If cmdF1 is a command button then the code cmdF1 = true is actually setting the VALUE of cmdF1 to true. That, in VB, triggers a click event. If all you want to do is enable the button when the F1 key is pressed then use cmdF1.enabled = true.
What you are doing with the code "cmdF1 = true" is effectively setting up a double-click event. That's probably why it executes twice, once with the keydown event as the cmfF1=true click event is triggered and once when you click it.
Hi,
I just tried to reproduce your problem and failed.
If there are any visible or enabled controls on a form then the form cannot get the focus so the code in KeyDown will not be executed. If the command button cmdF1 is not enabled and there are no other visible or enabled controls on the form, then the code in the cmdF1 click event is fired from your code in the form KeyDown event.
As hard as I tried I couldn't get it to run twice can you let us know some more details, I'm intrigued.
Phil
zoldy
09-14-2000, 02:02 PM
Ok if anyone would like to reproduce my problem to have a look at here is how.
Create a form
Add component Microsoft form 2.0 object Library
Then using the command button in that library add a command button. Note is is critical that you use this button and not the standard one.
Now add simple code to the commandbuttons click event
MsgBox "Hello"
This works great. And now for the problem
Set your forms keypreview property to true
Now in the forms keydown event insert the following code
If KeyCode = 112 Then CommandButton1 = True
Now run the Prject and Press F1
You get the "Hello" message twice . Or at least I do
:) ZOLDY :)
BillSoo
09-14-2000, 02:12 PM
Try:
If KeyCode = 112 Then
KeyCode = 0
CommandButton1 = True
End If
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
zoldy
09-14-2000, 02:27 PM
WOW .... cool that works .... why do you suppose I need to do that?
:) ZOLDY :)
BillSoo
09-14-2000, 03:10 PM
Well...since it only happens with the forms library button and not the regular command button, I assume that it has something to do with the way these controls process messages.
As a guess I would say that the form intercepts the keycode, processes it in the keydown event, then passes the keycode on to the control. Somehow, the control passes the value back to the form, where it gets processed again. Setting the keycode to 0 after processing it once ensures that it doesn't get processed further.
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder