Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Label toggle using ALT key

Status
Not open for further replies.

johnjrd

MIS
Jun 6, 2001
54
GB
Hi

Is there anyway to change the label.caption description for all labels on a form based on a key press for example the ALT key.

So if the ALT key is pressed all of the label captions change and if you let go it reverts to normal.

Ive used the function keys as short cuts to load forms before but never tried to alter the label caption based on a key press.

Is it possible ?
 
No, there's no way to trap the Alt key on its own - at least, not with native VFP funtions. You can trap almost all the "normal" keys (as opposed to the modifier keys like Alt and Ctrl), and you can trap these keys when pressed in conjunction with Alt (so you could trap Alt+A for example).

You can also test to see if Caps Lock, Num Lock or Ins is currently engaged. But you can't do that with Alt (as far as I know).

One option might be to use Ins rather than Alt as your trigger key. You could then use a timer which fires every so-many milliseconds, and calls INSMODE() to check if the key is currently down.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
But that doesn't really help. What you would need is for the Keypress event to trap the key, not INKEY().

I'll think you'll just have to designate a different key for this task. Say F2 for the sake of example. So, you set the form's KeyPreview to .T., and in the form's KeyPress event, you do something like this:

Code:
LPARAMETERS nKeyCode, nShiftAltCtrl
IF nKeyCode = -1
  * F2 was pressed
  IF THISFORM.lCaptionsModified
    * Captions have been modified, so un-modify them
  ELSE
   * Captions not yet modified, so do it now
  ENDIF
  THISFORM.lCaptionsModified = NOT THISFORM.lCaptionsModified
ENDIF

In this example, lCaptionsModified is a custom property of the form in which you store the current state of your captions toggle.

Hope this makes sense.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
If you want a turn-key ready solution (pardon the pun), Craig Boyd made a DLL before VFP had Bindevents, that in one sample is specialised on recording key strokes, independant on the application the key strokes would be adressed to...


Download the vfpex.fll mentioned there and look out for the code beginning with:
Code:
***************************************************
*!* GLOBAL KEYBOARD HOOK EXAMPLE
*!*
*!* Requires: vfpex.fll
*************************************************

You'd just need to find out what arrives in the Hookstruct variable in the wineventhandler() procedure, if you press ALT. And then only react to that input.

On the other hand with Bindevents you can really react to WM_KEYDOWN and WM_KEYUP differently, eg toggle labels on ALT pressed and toggle back, when ALT is released.

Bye, Olaf.
 
A point to remember about using the ALT key in this way is that the key is also used to access the menu bar - for example, Alt+F to open the File menu.

And it might be used in modal dialogues to activate certain conrols (e.g. Alt+S for Save).

If you use it for some other task - in this case, changing the captions - you would be going against these standards. That might not matter - it depends on the nature of your UI - but it's worth keeping mind.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Mike,

that's a good pint, but maybe that is the reason to want to toggle Labels, eg toggling from Save to Save or even Save (ALT+S), so you see what hotkeys trigger the functions described by the labels and button captions, if - but only if - you press ALT, instead of showing the underlined characters all the time.

Again, that is different from the standard, but might be wanted for a pure look, as long as the ALT key is not pressed.

Bye, Olaf.
 
Oh, and while a pint is a good thing too, I meant a good point of course. Nonstandard behaviour is something undermining a coherent user expereince throughout all applications under a certain OS.

MS is not very restrictive and that might change, when the transition to WPF is done, although the masses of properties available for WPF controls tend to be even less strictly defining user experience.

If my guess is right, I think this kind of caption toggling is something I would like to see throughout windows applications. Partly, because underlined single characters don't indicate being hotkeys in conjunction with ALT, if you don't know that, and partly because IF you know ALT+Some key can act as a hotkey for some button, pressing ALT to see, what additional key must be pressed is comfortable enough. You'll likely spot all the captions changing and it doesn't hinder you to press ALT+Somekey in the first place, as the hotkey is activated just in time.

Bye, Olaf.



 
Thanks

Managed to use the key press event using one of the function keys to toggle the label captions. It's a bit simple but seems to work.

Will have a look at the dll to see if that gives us better functionality.

Thanks again everyone,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top