Detecting pressed keys

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
jparada
Posts: 433
Joined: Fri Jan 23, 2009 5:18 pm

Detecting pressed keys

Post by jparada »

Hi,

In a window with some controls (without any control gets the focus), I would like to detect when the user presses keys (A. .. Z and 0 ... 9), to detect those keys and then "show" a textbox control (previously hidden) and set the value property of the textbox with the contents of the user keys pressed.

I hope I've explained well.

Please any advice for this implementation.

Best Regards
Javier
User avatar
mol
Posts: 3825
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Detecting pressed keys

Post by mol »

Helo Javier!
You can find fine example about iplementation of this idea in Calculator (placed some days ago by Vanguarda and changed by me).

Best regards, Marek
jparada
Posts: 433
Joined: Fri Jan 23, 2009 5:18 pm

Re: Detecting pressed keys

Post by jparada »

Hi Marek,

Please let me take a look.

Thanks.

Best Regards
Javier
User avatar
mol
Posts: 3825
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Detecting pressed keys

Post by mol »

Please, download:
download/file.php?id=820
and analyze it.

You will find lines:

Code: Select all

     @ 040,121 TEXTBOX ReadHide VALUE " "  WIDTH 15  HEIGHT 25 NOTABSTOP ON CHANGE EvalKeys() ON ENTER Operator_Click("=") INVISIBLE
 
   Calc.ReadHide.SetFocus()
*-------------------

Static Function EvalKeys()

	Local c_Keys
	if !Empty(Calc.ReadHide.Value)
		c_Keys := Alltrim(Calc.ReadHide.Value)
		do case
			case c_Keys == "0" .or.;
				 c_Keys == "1" .or.;
				 c_Keys == "2" .or.;
				 c_Keys == "3" .or.;
				 c_Keys == "4" .or.;
				 c_Keys == "5" .or.;
				 c_Keys == "6" .or.;
				 c_Keys == "7" .or.;
				 c_Keys == "8" .or.;
				 c_Keys == "9"
					Number_Click(Val(Alltrim(c_Keys)))
			case c_Keys == "/"
					Operator_Click("/")
			case c_Keys == "*"
					Operator_Click("X")
			case c_Keys == "-"
					Operator_Click("-")
			case c_Keys == "+"
					Operator_Click("+")
			case c_Keys == "."
					Decimal_Click()
			case c_Keys == "C" .or. c_Keys == "c"
					CancelEntry_Click()
			case c_Keys == "R" .or. c_Keys == "r"
					Cancel_Click()
			case c_Keys == "W" .or. c_Keys == "w"
					CancelMemo_Click()
			case c_Keys == "S" .or. c_Keys == "s"
					ReadMemo_Click()
			case c_Keys == "M" .or. c_Keys == "m"
					SMemo_Click()
			case c_Keys == "A" .or. c_Keys == "a"
					AddMemo_Click()
		end case
		Calc.ReadHide.Value := ""
	endif

Return Nil

User avatar
srvet_claudio
Posts: 2224
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: Detecting pressed keys

Post by srvet_claudio »

Hola Javier,
en:
viewtopic.php?f=15&t=1331&start=0&bookm ... 160c6be6ea
postee algunas funciones que leen la entrada del teclado, espero que te sean de alguna utilidad.
Un saludo cordial,
Claudio Soto.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
Post Reply