INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

API Functions

Intercepting CTRL+SHIFT+Enter by vgulielmus
Posted: 21 Feb 16

Some key combinations are not intercepted by keypress().
Some are intercepted only by the form's keypress() but not by the object's keypress() (like ALT+letter).
Also the menu's shortcuts can be ignored (like CTRL+A).
I wrote a little more about keypress here
Keypress and DODEFAULT() for textbox

In this case, CTRL+SHIFT+ENTER is used to run an executable as administrator.
Maybe this is the reason for not being intercepted by neither the form's, nor the object's keypress()

To intercept it, the wm_keyup message must be bind to the form's hwnd, and then the GetKeyState() function must be called.
If the highest bit of the returned value of GetKeyState() is equal to 1, then the key passed as parameter was pressed (CTRL or Shift)
I wrote a little more about binding wm_keyup message, here
Detect KeyUp like MouseUp()

Here is the solution for intercepting CTRL+SHIFT+Enter.

CODE --> Foxpro

DECLARE integer GetKeyState IN User32 integer
#define VK_RETURN 0x0d && Enter
#define VK_SHIFT 0x10 && Shift
#define VK_CONTROL 0x11 && Control

#define VK_LSHIFT 0xa0 && Left Shift
#define VK_RSHIFT 0xa1 && Right Shift
#define VK_LCONTROL 0xa2 && Left CTRL
#define VK_RCONTROL 0xa3 && Right CTRL

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
		BINDEVENT(This.HWnd,0x0101,This,"detectkeyup") && intercept keyup
	ENDPROC
	PROCEDURE detectkeyup
		LPARAMETERS p1,p2,p3,p4
		IF TYPE("This.ActiveControl") <> "U"
			IF This.ActiveControl = ThisForm.txt AND p3 = VK_RETURN AND BITTEST(GetKeyState(VK_SHIFT),7) AND BITTEST(GetKeyState(VK_CONTROL),7)
				* p3 = VK_RETURN  && 13 enter
				* place here the desired code
				* in this sample just type to the screen which shift and control (left or right) was pressed
				ACTIVATE SCREEN
				?BITTEST(GetKeyState(VK_LSHIFT),7),BITTEST(GetKeyState(VK_LCONTROL),7),BITTEST(GetKeyState(VK_RSHIFT),7),BITTEST(GetKeyState(VK_RCONTROL),7)
			ENDIF
		ENDIF
	ENDPROC
ENDDEFINE 

Please read
GetKeyState
Constants
WM_KEYUP

Vilhelm-Ion Praisach

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close