[Gambas-user] Class Key

Benoit Minisini gambas at ...1...
Mon Nov 12 13:59:26 CET 2007


On lundi 12 novembre 2007, David Villalobos Cambronero wrote:
> Hi all, it is just a small question... but as usual, I want to know why...
>
> I add this SUB to my Forms so they can be closed I the user press the ESC
> key:
>
> PUBLIC SUB Form1_KeyPress()
>
>     IF Key.Code = Key.Esc THEN
>         ME.Close()
>     END IF
>
> END SUB
>
> I thought this code should work:
>
>     IF Key.Esc THEN
>
>         ME.Close()
>
>     END IF
>
>     ... And actually does, but the Form is closed if you press: ESC, ALT,
> TAB, SHIFT and BLOQ.
>
> I now Key.Esc is a Constant not a Property, but I you press A, B, F1, etc,
> the Form isn't closed.
>
> My question is: Why if we press: ESC, ALT, TAB, SHIFT and BLOQ, Key.Esc
> returns TRUE, and if we press: A, B, F1, etc, it retuns FALSE?
>
> I don't know if it is a bug or I'm doing something wrong...
>
> Best regards...
>
> David
>

Key.Esc is a constant, it always returns the same thing (a non-zero value, so 
the test is always TRUE). 

Check when Form1_KeyPress is really called instead.

Regards,

-- 
Benoit Minisini




More information about the User mailing list