• Welcome to PlanetSquires Forums.
 

FReebasic Keypreview

Started by Petrus Vorster, September 27, 2016, 04:34:43 PM

Previous topic - Next topic

Petrus Vorster

It would be very cool if we could get the old VB function of a Keypreview on any form.
I still need keypresses in many tools and the old keypreview made it possible in a single click and a normal function on each form.
No need to catch it in the message pump or figuring out where to catch a key.

This is really a function i would greatly be thankful for.
-Regards
Peter

Paul Squires

As you've indicated, the best way to do this is to catch the keypress in the FF_PUMPHOOK checking the incoming Windows message and then check to see if it belongs to the HWND of the control you are interested in.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Petrus Vorster

Maybe, but that keypreview was incredibly handy.
I assume it would be difficult to make or else someone would have done so already.
Still a feature i would love to have just for just how it simplifies key trapping.
-Regards
Peter

David Kenny

If you really need it, you can add it yourself.  As Paul said, you can catch it in the all keys FF_PUMPHOOK routine, but then you could forward it on to another routine that would look at what form and control it's from and then pass it on to any other routines that requested a preview of keys bound for a certain form or a certain control, or a class/subset of controls (all editbox's for example).

Petrus Vorster

 ;)
I don't have any idea how to do that.
Would like to see how one can do something like that.
I have looked at key trapping in FF, but i find it vague on how to crate something that can be universally applied to all forms or across the project.
The old Vb6 routine made that very easy for novices like myself.
:-[
-Regards
Peter

José Roca

> I don't have any idea how to do that.

Easy. Write a class for each kind of control that you want to support. In the class, subclass the Windows control (e.g. for MyEditClass -or wathever- subclass the Edit control, etc.). In the window procedure of the subclassed control catch messages like WM_CHAR (for KeyPress), WM_KEYUP (for KeyUp), WM_KEYDOWN (for KeyDown), WM_LBUTTOUP or WM_LBUTTONDOWN and send a message to the parent window before processing them.

Not very difficult, but a daunting task if you have to write classes for all the controls.

VB 6 used subclassed controls implemented in the runtime or in OCXs.