www.pudn.com > matlab7.x.rar > wgfcnkey.cpp


/*================================================================= 
 * wgfcnkey ---- traps pressing of function keys (F1, F2, ..., F12)  
 * and Shift, Ctrl, Alt keys in an MATLAB figure window 
 *  
 * Use this command-line to compile in MATLAB: 
 * mex wgfcnkey.cpp user32.lib 
 * 
 * Input ---- None 
 * Output ---- a scaler 
 *           = 0, no function was pressed 
 *           = 1, F1 was pressed 
 *           ... 
 *           = 12, F12 was pressed 
 *			 = 13, left Shift was pressed 
 *			 = 14, left Ctrl was pressed 
 *			 = 15, left Alt was pressed 
 *			 = 16, right Shift was pressed 
 *			 = 17, right Ctrl was pressed 
 *			 = 18, right Alt was pressed 
 * 
 * Created by: Dong Weiguo, 22 Jan. 2004 
 * Updated on 29 Jan. 2004, included the left and right instances of  
 * Shift, Ctrl, and Alt keys. 
 *  
 *=================================================================*/ 
/* $Revision: 1.10 $ */ 
#include  
#include "mex.h" 
 
void mexFunction( int nlhs, mxArray *plhs[],  
		  int nrhs, const mxArray*prhs[] ) 
      
{  
	double *x; 
	char *input_buf; 
	int   buflen,status; 
 
    /* Check for proper number of arguments */ 
	if (nrhs >= 1) {  
	mexErrMsgTxt("No input argument required.");  
    } 
 
	/* create output array*/ 
	plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL); 
 
	x = mxGetPr(plhs[0]); 
	x[0] = 0.0; 
 
    /* Do the actual computations in a subroutine */ 
	/* 
	HWND hWnd; 
	hWnd = FindWindow(NULL, input_buf); 
	MSG msg; 
	//PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE); 
	//GetMessage(&msg, hWnd, 0, 0); 
	 
	TranslateMessage(&msg); 
    DispatchMessage(&msg); 
	if (msg.message == WM_KEYDOWN) 
	{ 
		switch(msg.wParam) 
		{ 
		case VK_F1: 
			//AfxMessageBox("Test"); 
			x[0] = 1; 
		} 
	}	 
	*/ 
	//x[0] = GetKeyState(VK_F1); 
	int i; 
	short keystatus = 0; 
	for (i = VK_F1; i