[Gambas-user] about key check

GuruLounge - MailLists maillists at ...1367...
Mon Apr 17 11:17:04 CEST 2006


You generally have to use the KeyPress event of a particular control
then read the "key.code" integer for the key that was pressed.  There
are a number of constants related to different keys.  I've browsed the
info under "help".

I should note that I've had trouble with the "ENTER" key.  The keypad
ENTER and regular ENTER have different codes so I've had to monitor them
with the direct values 4100 and 4101 which isn't recommended.

All the same I still scan for regular ASCII codes when using "key.code".

example:

PUBLIC SUB textbox1_KeyPress()

	intkeycode = key.code

	if ((intkeycode = 4100) or (intkeycode = 4101)) then
		'ENTER key was pressed (keypad or regular).
	endif

	if ((intkeycode > 96) and (intkeycode < 123)) then
		'lowercase letter
	endif

	if ((intkeycode > 64) and (intkeycode < 91)) then
		'UPPERCASE LETTER
	endif

	if ((intkeycode > 47) and (intkeycode < 58)) then
		'number
	endif


END

HTH,
Jeff

On Mon, 2006-04-17 at 15:19 +0800, hendri wrote:
> can someone lead me to an example of how I can check for keyboard's
> keypressed so I can trap for :
> 
> 01. upper case only when user type something, and
> 02. permits only numeric input
> 
> thanks.

-- 

     .^.
     /V\
    /( )\
    ^^-^^
Linux Advocate





More information about the User mailing list