📄 keyset.cpp
字号:
#include "stdafx.h"
#include "cfgfile.h"
HWND hKeyDlgWnd;
char ArrKeyCode[255][5];
int iKeyIndex;
int i;
int iFlag=0;
HWND m_NumLock;
HWND m_edKeyText;
BOOL m_blFindFile=TRUE;;
void GetKeyWnd()
{
m_NumLock=GetDlgItem(hKeyDlgWnd,IDC_STATIC_NumOn);
m_edKeyText=GetDlgItem(hKeyDlgWnd,IDC_EDIT2);
}
void InitKeyDlgItem()
{
FILE *fP;
int j;
memset(ArrKeyCode,0,sizeof(ArrKeyCode));
//* Open file in text mode: *//
if( (fP = fopen( "\\disk\\msp.kbd", "rb" )) != NULL ){
//* Read file record (KeyCode) to Array[255][5] from fP *//
for (i=0;i<255;i++)
for (j=0;j<5;j++)
fread( &ArrKeyCode[i][j], 1, 1, fP );
fclose(fP);
}
else{
if((fP=fopen("\\disk\\msp.kbd","wb"))==NULL){
MessageBox(hKeyDlgWnd,_T("File could not be opened"),NULL,MB_OK);
m_blFindFile=FALSE;
}
else{
fwrite(ArrKeyCode,sizeof(ArrKeyCode),1,fP);
fclose(fP);
}
}
//*set NumLock value (init).
SetWindowText (m_NumLock,_T("ON"));
}
void OnKeyApp()
{
TCHAR cKeyCode[5];
if(m_blFindFile==FALSE){
MessageBox(hKeyDlgWnd,_T("File msp.kbd could not be opened"),NULL,MB_OK);
return;
}
if(iKeyIndex==0){
MessageBox(hKeyDlgWnd,_T("Please select a key"),NULL,MB_OK);
return;
}
//set array[5] from control text
GetWindowText(m_edKeyText,cKeyCode, 5);
if (cKeyCode[0]==94 && cKeyCode[1]==91)
{
cKeyCode[0]=27;
cKeyCode[1]=cKeyCode[2];
cKeyCode[2]=cKeyCode[3];
cKeyCode[3]=cKeyCode[4];
cKeyCode[4]=0;
}
else if (cKeyCode[0]==94)
cKeyCode[0]=17;
else if (cKeyCode[0]=='\\'){
cKeyCode[0]=0;
for(i=1;i<5;i++){
if(cKeyCode[i]==0)
break;
cKeyCode[0]=cKeyCode[0]*10+cKeyCode[i]-48;
}
cKeyCode[1]=0;
}
for (i=0;i<5; i++){
if(cKeyCode[i]==' ')
cKeyCode[i]=0;
ArrKeyCode[iKeyIndex-1][i]=(char)cKeyCode[i];
}
}
void OnKeyOk()
{
FILE *fP;
char p;
if(m_blFindFile==FALSE){
MessageBox(hKeyDlgWnd,_T("File msp.kbd could not be opened"),NULL,MB_OK);
return;
}
if( (fP = fopen( "\\disk\\msp.kbd", "wb" )) != NULL )
{
p=fwrite( ArrKeyCode, 1275,1,fP);
fclose(fP);
}
else
MessageBox(hKeyDlgWnd,_T("File could not be opened"),_T(""),MB_OK);
}
void OnBtNum()
{
if(m_blFindFile==FALSE){
MessageBox(hKeyDlgWnd,_T("File msp.kbd could not be opened"),NULL,MB_OK);
return;
}
if (iFlag==0)
{
iFlag=1;
SetWindowText (m_NumLock,_T("OFF"));
}
else
{
iFlag=0;
SetWindowText (m_NumLock,_T("ON"));
}
SetWindowText (m_edKeyText,_T(""));
}
void OnButton(WORD wParam)
{
// TODO: Add your control notification handler code here
char cKeyCode[5];
if(m_blFindFile==FALSE){
MessageBox(hKeyDlgWnd,_T("File msp.kbd could not be opened"),NULL,MB_OK);
return;
}
iKeyIndex=wParam;
if (iFlag==0)
{
iKeyIndex=iKeyIndex-1000;
}
else
{
switch(iKeyIndex)
{
case 1096:iKeyIndex=1245; break;
case 1097:iKeyIndex=1235; break;
case 1098:iKeyIndex=1240; break;
case 1099:iKeyIndex=1234; break;
case 1100:iKeyIndex=1237; break;
case 1101:iKeyIndex=1212; break;
case 1102:iKeyIndex=1239; break;
case 1103:iKeyIndex=1236; break;
case 1104:iKeyIndex=1238; break;
case 1105:iKeyIndex=1233; break;
case 1110:iKeyIndex=1246; break;
default:iKeyIndex=iKeyIndex;
}
iKeyIndex=iKeyIndex-1000;
}
//get keycode from array[255][5];
if (ArrKeyCode[iKeyIndex-1][0]==27 )
{
cKeyCode[0]=94;
cKeyCode[1]=91;
for (i=0;i<3;i++)
cKeyCode[i+2]=ArrKeyCode[iKeyIndex-1][i+1];
}
else if (ArrKeyCode[iKeyIndex-1][0]==17 )
{
cKeyCode[0]=94;
for (i=0;i<4;i++)
cKeyCode[i+1]=ArrKeyCode[iKeyIndex-1][i+1];
}
else if((ArrKeyCode[iKeyIndex-1][0]<0x20||ArrKeyCode[iKeyIndex-1][0]>=127)&&ArrKeyCode[iKeyIndex-1][0]!=0){
sprintf(cKeyCode,"\\%d",ArrKeyCode[iKeyIndex-1][0]);
}
else
for (i=0;i<5;i++)
cKeyCode[i]=ArrKeyCode[iKeyIndex-1][i];
#ifdef UNICODE
TCHAR wcKeyCode[5];
mbstowcs(wcKeyCode,cKeyCode,sizeof(wcKeyCode));
SetWindowText(m_edKeyText,wcKeyCode);
#else
SetWindowText(m_edKeyText,cKeyCode);
#endif
}
LRESULT CALLBACK KeySet(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
WORD wCmd;
switch (message)
{
case WM_INITDIALOG:
hKeyDlgWnd=hDlg;
GetKeyWnd();
InitKeyDlgItem();
return TRUE;
case WM_COMMAND:
wCmd=LOWORD(wParam);
switch(wCmd){
case IDC_BUTTON144: //NumLk
OnBtNum();
break;
case IDC_BUTTON200: //change
OnKeyApp();
break;
case IDC_BUTTON202: //ok
OnKeyOk();
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
break;
case IDC_BUTTON204:
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
default:
if(wCmd>=IDC_BUTTON8&&wCmd<=IDC_BUTTON218)
OnButton(wCmd);
break;
}
break;
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -