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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Intercepting CTRL+SHIFT+Enter 4

Status
Not open for further replies.

vgulielmus

Programmer
Jan 27, 2014
522
RO
Posted here faq184-7867 a solution for intercepting CTRL+SHIFT+Enter.
The technique can be used for any other key combination, undetected by the keypress() event

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

 
This is helpful. Reminds me of a blog article...

Before BINDEVENTS to windows messages was available in VFP9 Craig Boyd posted about how to make use of Windows API to handle key input and much more:

The FLL mentioned there can also be used in VFP6, if not even older versions. Nevertheless it's good to be able to bind to windows messages and the solutions.app has some very good samples for this feature, too.

Bye, Olaf.
 
Thank you for you appreciations and for the additional resources.
The detection of keyup() was requested a couple of times, and recently intercepting CTRL+SHIFT+Enter.

I've tried to bind both WM_keyup and WM_keydown.
The code is almost identical, except the value for WM_keydown, which is 0x0100 instead of 0x0101.
But WM_keydown has some drawbacks. The navigational keys, like arrows, are inhibited.
I don't know the reason.
Anyway, WM_keyup seemed to work fine.

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

 
@vgulielmus, provided example Ctrl key works fine. How to trap ALT key ?
 
Interesting question
I tried the code poste in the faq using the following constants, but with no luck.
#define VK_LMENU 0xa4
#define VK_RMENU 0xa5

Still, the ALT+key combinations (excepting the menu shortcuts) can be intercepted in the form's keypress() event.

Code:
ofrm = CREATEOBJECT("MyForm")
ofrm.show()

DEFINE CLASS MyForm as Form
	ADD OBJECT txt as textbox && the desired object 
	ADD OBJECT cmd as commandbutton WITH top = 50
	PROCEDURE keypress
		LPARAMETERS nKeyCode, nShiftAltCtrl
		IF m.nShiftAltCtrl = 4
			ACTIVATE SCREEN
			?m.nKeyCode
		ENDIF
	ENDPROC
ENDDEFINE

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

 
Thank you

ALT+key combinations

Again your sample code works fine but I am looking for something like this. Please try following code. Press only <Ctrl> key and count 5 you would notice <CommandButton> would disappear and when you <Ctrl> key UP it is visible again. So Same I was trying with only <ALT> key.

Code:
PUBLIC ofrm
ofrm = CREATEOBJECT("MyForm")
ofrm.show()
DEFINE CLASS MyForm as Form
	ADD OBJECT txt as textbox && the desired object 
	ADD OBJECT cmd as commandbutton WITH top = 50
	PROCEDURE Init
        DECLARE integer GetKeyState IN User32 integer
		BINDEVENT(This.HWnd,0x0101,This,"DetectKeyUp")
		BINDEVENT(This.HWnd,0x0100,This,"DetectKeyDn")
	ENDPROC
	PROCEDURE DetectKeyDn(p1,p2,p3,p4)
	   this.cmd.Visible=.F.
	PROCEDURE DetectKeyUp(p1,p2,p3,p4)
	   this.cmd.Visible=.T.		
ENDDEFINE

Thank you
 
So Same I was trying with only <ALT> key.

This should just be a question of changing the relevant codes:

Code:
PUBLIC ofrm
ofrm = CREATEOBJECT("MyForm")
ofrm.show()
DEFINE CLASS MyForm as Form
	ADD OBJECT txt as textbox && the desired object 
	ADD OBJECT cmd as commandbutton WITH top = 50
	PROCEDURE Init
        DECLARE integer GetKeyState IN User32 integer
		BINDEVENT(This.HWnd,[b]0x0105,[/b]This,"DetectKeyUp")
		BINDEVENT(This.HWnd,[b]0x0104,[/b]This,"DetectKeyDn")
	ENDPROC
	PROCEDURE DetectKeyDn(p1,p2,p3,p4)
	   this.cmd.Visible=.F.
	PROCEDURE DetectKeyUp(p1,p2,p3,p4)
	   this.cmd.Visible=.T.		
ENDDEFINE

Give it a try.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
But it doesn't seem to work as expected if you hold down Alt and then press a letter that corresponds to a menu accelerator, such as Alt+F for the File menu. Then again, that wasn't in the brief.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
@Mike, Very good, Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top