⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wgfcnkey.cpp

📁 一个matlab mex 文件
💻 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 <windows.h>
#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<VK_F13; ++i)
	{
		keystatus = GetKeyState(i);
		if (keystatus < 0)
		{
			x[0] = i - VK_F1 + 1;
			break;
		}
		else
		{
			keystatus = 0;
		}
	}
	
	if (GetKeyState(VK_LSHIFT) < 0)
	{
		x[0] = 13;
	}

	if (GetKeyState(VK_LCONTROL) < 0)
	{
		x[0] = 14;
	}

	if (GetKeyState(VK_LMENU) < 0)
	{
		x[0] = 15;
	}

	if (GetKeyState(VK_RSHIFT) < 0)
	{
		x[0] = 16;
	}

	if (GetKeyState(VK_RCONTROL) < 0)
	{
		x[0] = 17;
	}

	if (GetKeyState(VK_RMENU) < 0)
	{
		x[0] = 18;
	}

	//x[0] = GetAsyncKeyState(VK_F1);
	return;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -