Activating controls by ALT+... hotkey

Moderator: Rathinagiri

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

Activating controls by ALT+... hotkey

Post by mol »

I've started to work with my new app. I prefer keyboard to work with computers, so I've defined hotkey for almost controls in my program.
And found, that sometimes, after pressing hotkey defined with alt key, alt activates menu too.
This is very troublesome, because thirst character of entered date is missing.

I've prepared a little sample. Try to compile it and then, try to use ALT-T key to activate textbox and enter some numbers.
Try to do it few times, because this is a lottery - sometimes works good, sometimes bad.
I've especially defined main menu to watch when it's activated.

Code: Select all

#include "hmg.ch"
Function Main

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 240 HEIGHT 480 ;
		TITLE 'HMG Demo' ;
		MAIN 

		DEFINE MAIN MENU
		    POPUP "&Option"
		        MENUITEM  'Any Option '
		    END POPUP
		END MENU

		@ 15,10 LABEL l1 ;
			VALUE "Press ALT-&T to activate textbox" ;
			width 200
			
		@ 40,10 TEXTBOX Text_1 ;
			VALUE 123 ;
			TOOLTIP 'Numeric TextBox' ;
			NUMERIC ;
			MAXLENGTH 5 ;
			RIGHTALIGN

		@ 80,10 TEXTBOX Text_2 ;
			VALUE "another textbox..." 
			MAXLENGTH 55 
			
		DEFINE BUTTON Text1SetFocus
			ROW	150
			COL	20
			WIDTH	200
			HEIGHT	40
			CAPTION	'Set focus to Text_1 by button'
			ACTION	Form_1.Text_1.SetFocus
		END BUTTON


	END WINDOW

	Form_1.Center

	ON KEY ALT+T OF FORM_1 ACTION FORM_1.TEXT_1.SETFOCUS
	
	Form_1.Activate

Return Nil

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

Re: Activating controls by ALT+... hotkey

Post by mol »

I think, a little delay for releasing ALT by user after processing ALT-... would be useful...
But, I don't know how to do it :)
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: Activating controls by ALT+... hotkey

Post by dhaine_adp »

Hi Mol,

Pressing ALT alone will surely activate menu bar. It is windows default behaviour for that key.

An alternate method to achieved the same ALT+T to your Apps is to utilized ACTION/ONLICK events of LABEL control.
Example:

Code: Select all

From your code:

      @ 15,10 LABEL l1 ;
         VALUE "Press ALT-&T to activate textbox" ;
         width 200 ACTION LblAction()


static function LblAction()

     FORM_1 ACTION FORM_1.TEXT_1.SETFOCUS
     return nil


Well you can do additional process before you pass the control to the text box if you wish... However the code snippet is not tested it's just to illustrate my point and maybe perhaps you can eliminate the ON KEY statement.

Regards,

Danny
Regards,

Danny
Manila, Philippines
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Activating controls by ALT+... hotkey

Post by mol »

It seems to work excellent! Great and simple!
THX Danny!

Marek
Mario Mansilla
Posts: 269
Joined: Wed Aug 13, 2008 2:35 pm
Location: Córdoba - Argentina

Re: Activating controls by ALT+... hotkey

Post by Mario Mansilla »

Hola Makek :
Este problema tambien se manifiesta cuando usas teclas de acceso rapido en el control toolbar , ya que tambien usan ON KEY . Esto se manifiesta anulando el primer caracter o numero que ingresas en el control textbox al cual le das el foco y tal cual manifiestas esto lo hace aleatoriamente , no he podido encontrar un ciclo determinado que lo provoque.
Esto deja de manifestarse cuando el ALT+Tecla lo haces lentamente , pero hay operadores que son muy veloces .
Saludos .
Mario Mansilla

Hello Makek:
This problem also occurs when you use hot keys on the control toolbar, and that also use ON KEY. This is manifested by canceling the first character or number you enter in the textbox control to which you give the focus and as is obvious this is done randomly, I could not find a given cycle causes it.
This leaves to manifest when you do ALT + key slowly, but operators are very fast.
Greetings.
Mario Mansilla
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Activating controls by ALT+... hotkey

Post by mol »

I've tested Danny's idea on Windows XP and worked OK.
But, now, I'm trying it on Windows 7 and it works only when I click with mouse on label, but does not work with keyboard hotkey.
Maybe Roberto will know what's going on?
Why labels are not activated by hotkey in Win'7?
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: Activating controls by ALT+... hotkey

Post by dhaine_adp »

Hi Mol,

Do you have any running policies on your workstation? Are all those standard Windows Hotkeys is not working or those apps from HMG only? If this is local to HMG Apps perhaps you are right Roberto can shed some light in it. Otherwise please check you registry settings at:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies
The value is: NoWinKeys (DWORD Value)
Please set it for: Set to 1 = Hotkeys disabled. Set to 0 = Hotkeys enabled

Danny
Regards,

Danny
Manila, Philippines
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Activating controls by ALT+... hotkey

Post by mol »

dhaine_adp wrote:Hi Mol,

Do you have any running policies on your workstation? Are all those standard Windows Hotkeys is not working or those apps from HMG only? If this is local to HMG Apps perhaps you are right Roberto can shed some light in it. Otherwise please check you registry settings at:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies
The value is: NoWinKeys (DWORD Value)
Please set it for: Set to 1 = Hotkeys disabled. Set to 0 = Hotkeys enabled

Danny
I'll test it later.
Now, I'm working on XP. I've modified a little previous sample to test it on XP. It works fine - but clicking by mouse on labels causes NO action. Only hotkeys are working - reverse behavior form win'7.

My new code

Code: Select all

#include "hmg.ch"
Function Main

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 240 HEIGHT 480 ;
		TITLE 'HMG Demo' ;
		MAIN 

		DEFINE MAIN MENU
		    POPUP "&Option"
		        MENUITEM  'Any Option '
		    END POPUP
		END MENU

		@ 15,10 LABEL l1 ;
			VALUE "Press ALT-&T to activate textbox" ;
			width 200 ;
			Action Form_1.Text_1.SetFocus
			
		@ 40,10 TEXTBOX Text_1 ;
			VALUE 123 ;
			TOOLTIP 'Numeric TextBox' ;
			NUMERIC ;
			MAXLENGTH 5 ;
			RIGHTALIGN

		@ 80,10 LABEL l2 ;
			VALUE "Press ALT-&N to activate textbox 2" ;
			width 200 ;
			Action Form_1.Text_2.SetFocus
			
		@ 105,10 TEXTBOX Text_2 ;
			VALUE "another textbox..." 
			MAXLENGTH 55 
			
		@ 140,10 LABEL l3 ;
			VALUE "Press ALT-&K to activate textbox 3" ;
			width 200 ;
			Action Form_1.Text_3.SetFocus
		@ 165,10 TEXTBOX Text_3 ;
			VALUE "textbox 3" 
			MAXLENGTH 55 

	END WINDOW

	Form_1.Center
	
	Form_1.Activate

Return Nil


User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: Activating controls by ALT+... hotkey

Post by dhaine_adp »

Hi Mol,

I don't know if I am wrong but the way I understood the Windows accelerator keys or ALT+<Key> are just shortcuts.
but clicking by mouse on labels causes NO action
If your plan is to display an image in place of the label or something then it is really a problem. On the otherhand if your intention is to set focus on the text box, I think it is much easier to click on the Text box which is a norm in data entry routine. Users will not notice that at all because they knew that labels are just labels and they cannot use it for data entry. Anyway, from HMG's Standard Syntax for LABEL control, please try this if it will work for you:

Again from you code:

Code: Select all

From your code:

      @ 15,10 LABEL l1 ;
         VALUE "Press ALT-&T to activate textbox" ;
         width 200 ACTION LblAction() ONCLICK LblAction()


static function LblAction()

     FORM_1.TEXT_1.SETFOCUS
     return nil

Regards,

Danny
Regards,

Danny
Manila, Philippines
Post Reply