Página 1 de 1

Trying to detect ALT + key in Form ....

Publicado: Vie Feb 05, 2016 12:55 pm
por ChrisGillard
Hi,

Am exploring how to make Buttons or Prompts respond to mouse clicks and key presses including ALT+Key combinations .... maybe enhanced TButtons or maybe TLabel/TLabelEx made into buttons.

I have looked at how TButton uses the & to give it an Action Key and how this adds the Key to an array ::aShortcut in TForm.

I would like to Add ALT+key combinations to be Action keys in the form.

I could have a ::aAltKeys in an inherited TForm and Add and Remove oControls like in ::aShortcut .... this would be quite elegant and 'correct'.

Then I need to detect the ALT+key and scan my ::aAltKeys.

Problem here is I have not found a way to detect the ALT+Keys at form level usinf say FormKeyDown() or FormChar() ..... is there a way I can use?

or I could use XA_SetKey() again adding and deleting ALT+keys as necessary ..... no very elegant and not very 'correct' .... but maybe my best chance?

Another question .... do we have the source to XA_SetKey(), I can't find it and it might be useful to me?

Any thoughts would be appreciated.

Thanks

Chris

Re: Trying to detect ALT + key in Form ....

Publicado: Vie Feb 05, 2016 1:06 pm
por jfgimenez
Chris,

there is no OnSysKeyDown event in the form, but you may override the method WMSysKeyDown:

Código: Seleccionar todo

METHOD WMSysKeyDown( nKey, nFlags ) CLASS TForm1

   IF nKey == VK_F2   // Alt+F2
   	// Do something...
   ENDIF
   
RETURN Nil

Re: Trying to detect ALT + key in Form ....

Publicado: Vie Feb 05, 2016 5:39 pm
por ChrisGillard
Jose,

Thank you for the reply and suggestion.

I probably want to detect ALT + anykey and then scan an array of Keys & Action pairs to execute the action.

I will do some testing.

Have a good weekend, thanks again.

Chris

Re: Trying to detect ALT + key in Form ....

Publicado: Vie Feb 05, 2016 6:34 pm
por ChrisGillard
Jose,

I have had ago, below is my code and what I see using LogDisplay()

Do you expect to get the Alt and the other key as 2 actions? I'm sure I can cope if that's the way it is.

Alt A and Alt B give sensible nKey for the A & B, always upper case but that's fine.

Alt F2 gives me a 'q' for a character, lower case. Other Al Fkeys give different ascii so could easily be detected and converted to F1, F2, F3 etc.

I think its workable, is this how it should be?

Definitely progress.

Thank you.

Chris