Página 1 de 1

TButtons or similar with active keys?

Publicado: Jue Jun 11, 2015 9:57 pm
por ChrisGillard
Hi,

It looks to me that TButtons and FlatButtons etc do not have a way of being actioned by a keyboard character, probably?

If I want the TButtons to be in a TToolbar and I would like the buttons to be actioned by a keyboard character also .... Is a parallel set of XA_SetKey() functions the best way of trying to simulate keypress actions in a TToolbar of TButtons?

Maybe I can subclass TToolbar and add some 'Action key' info to TButton:cargo .... something like that?

I still believe that keypresses can be a valuable part of very productive applications.

Any guidance would be appreciated.

Chris Gillard

Re: TButtons or similar with active keys?

Publicado: Vie Jun 12, 2015 2:14 pm
por ChrisGillard
Some progress,

If I set the button text to "&View" or "&Add" .... I get an underline on the letter after the & and it becomes an action key with ALT+V etc.

I now remember the '&' technique from many years ago.

That's a start of what I want.

In an ideal world I would be able to colour the action letter in red also ... but that's maybe too much to ask?

Maybe I can get to the canvas and write my own text?

Chris

Re: TButtons or similar with active keys?

Publicado: Sab Jun 13, 2015 5:16 pm
por ignacio
Hello,

I suggest you simply trap the keyboard events at the form level. To fire the buttons event manually just call its click event.

Regards

Re: TButtons or similar with active keys?

Publicado: Jue Jun 18, 2015 9:10 am
por ChrisGillard
Hi Ignacio,

I will do as you suggest and trap the keyboard events from the form and fire the button events in code.

Thank you for the suggestion.

Chris

Re: TButtons or similar with active keys?

Publicado: Jue Jun 18, 2015 4:45 pm
por ChrisGillard
Hmm trapping the onChar event of the form is not going to be ideal for this what I have in mind.

I am writing a Class, inherited from TPanel, that you will call from code, and this class will contain several buttons that will have their own onClick events but I need some way of calling those same events with keyboard characters.

It's a little bit like a TDbNavigator with its buttons being able to also respond to keyboard input by just placing the control on the form ... no extra code in the Form:OnChar event.

Ideally I dont want to do anything in the Form, I would like my class to be able to listen & respond to the characters that are being detected by the low level windows keyboard event handling.

I think I want to listen to the Windows keyboard messages and if my Class is in 'focus' I need to detect any keyboard characters.

I need my class to listen for characters, not be told what to do by onChar of the form.

Something like that. You must do this sort of clever stuff!

Chris

Re: TButtons or similar with active keys?

Publicado: Dom Jun 21, 2015 9:10 pm
por jfgimenez
Chris,

if you're writing your own class, inherited from any Xailer's control or from TControl itself, the easiest way to trap key strokes is by overwriting the WMKeyDown() method. Even if this control is a "container control", which can hold other controls on top of it, it will always be called when the key pressed is not processed and/or "stopped" by the child control which has focus. That is, if a child control process a key stroke and returns 0, its parent doesn't see that key stroke, but any other case it does.

So, try to overwrite the WMKeyDown() method to process any key you want, and don't forget to end it with ::Super:WMKeyDown( nKey, nFlags, hWnd )

BTW, the same applies to WMChar() also.

Re: TButtons or similar with active keys?

Publicado: Mar Jun 23, 2015 8:03 am
por ChrisGillard
Jose,

Thank you for that idea. I think that is what I need.

I am trying write something Like a TDbNavigator with number of buttons but also with keyboard action.

Overriding WMKeyDown() or WMChar() seems like the way to go.

Thank you very much.

Chris