Keydown, Keypress and No RETURN trapped.

03-30-2003, 04:08 AM
Hello All,

Got a problem using Visual Basic 6 and trying to trap the return key in my program.

According to me documentation it should be possible using either the Keydown, Keyup or Keypress event, as long as I make sure none of the command buttons default properlty is set.

Tried this, but it won't work. Only if I type a shifted return, the Keydown, Keyup or Keypress events are triggered. Even stranger is that it is capable of trapping the Esc key, so basically all is allright I'd guess..... I went back to a small test program with 1 form and 1 command button and even there it won't work unless with shifted return.

The reason I need this is that the user of the program must be able using the Tab key to navigate through all command buttons and when a button has focus, by pressing the return key activate its code.

All is basically simple and straight forward code, IF the Keydown, KeyUp or Keypress events were triggered.

Anybody have any idea what I doing wrong :confused: Its probably something stupid and small, but its currently frustrating me a lot.

Thanks for any help offered.

Regards, Leon

PS, If of importance, VB installed here is part of the VS 6 enterprise edition and installed in English using w2k with an English US keyboard.

03-30-2003, 08:16 AM
If you will set the KeyPreview to True for the form it will probably work
for you. Don't forget to set the keycode = 0 or you will get that
annoying beep.

03-31-2003, 12:21 AM

Thanks for the tip, but that didn't work either. I found it before when I searched your forum for me problem and tried it.

It's so strange. I just don't get it to be honest. The return key is the only one not triggering the Keydown, Keyup or Keypress events. The default property for all command buttons is false so that can't cause it. Went back to 1 form and 1 command button producing exactly the same problem. Only the shifted return triggers the Keydown, Keyup or Keypress events and produces 13 as Ascii or Keycode :confused: .

I'm baffled to be honest :confused: . What am I doing wrong :huh: ? Might a w2k configuration setting cause this?

Any other hints or tips are greatly appreciated.

Regards, Leon

03-31-2003, 01:57 AM
Just to make matters even more interesting. I've just tried using only 1 form. No commmand buttons on it, nothing at all. To my surprise the return key is now triggering the Keydown, Keyup and Keypress events.

This behavior equals to a commmand button being set as default, which there is NONE. As soon as a command button is put on the form, set with default to false, the return key will not trigger the Keydown, Keyup and Keypress events :confused: .

HELP!! :huh:

Regards, Leon

03-31-2003, 06:01 AM
Mmmmmmmmmm, well just found the answer in a very very old message from Ngenius.
BillSoo mentions there that windows will not trigger a Keypress, Keydown or Keyup event for the return or enter key if the active control is a command button. Instead it triggers a MouseClick event. How more obvious can it be :o :eek: !!!!!!! I almost feel stupid :chuckle: . Aaah wait, I do feel stupid ;) .

I use the MouseUp event to run my code. I want the code to activate only if the mousebutton is released over the command button. In this way the user, when he changes his mind while already having clicked the command button, can still steer away from it by releasing the mousebutton next to the command button. Same for accidental clicks. As such the MouseClick event has nothing and thats causing all me frustrations.

Thanks for the tip Thinker and the answer BillSoo.

Regards, Leon

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum