//定义结构体
typedef struct
{
int m_srcName;
char m_dstName;
}SKey;
static SKey KeyList[] =
{
//src:0x14c0c0eb dst:'a'
{0x14c0c0eb, 'a'}, //0
{0x24c0c0db, 'b'},
{0x34c0c0cb, 'c'},
{0x44c0c0bb, 'd'},
{0x54c0c0ab, 'e'},
{0x64c0c09b, 'f'},
{0x74c0c08b, 'g'},
{0x84c0c07b, 'h'},
{0x94c0c06b, 'i'},
{0xa4c0c05b, 'j'},
{0xb4c0c04b, 'k'},
{0xc4c0c03b, 'l'},
{0xd4c0c02b, 'm'},
{0xe4c0c01b, 'n'},
{0xf4c0c00b, 'o'},
{0x05c0c0fa, 'p'},
{0x15c0c0ea, 'q'},
{0x25c0c0da, 'r'},
{0x35c0c0ca, 's'},
{0x45c0c0ba, 't'},
{0x55c0c0aa, 'u'},
{0x65c0c09a, 'v'},
{0x75c0c08a, 'w'},
{0x85c0c07a, 'x'},
{0x95c0c06a, 'y'},
{0xa5c0c05a, 'z'}, //25
{0x13c0c0ec, '1'},
{0x23c0c0dc, '2'},
{0x33c0c0cc, '3'},
{0x43c0c0bc, '4'},
{0x53c0c0ac, '5'},
{0x63c0c09c, '6'},
{0x73c0c08c, '7'},
{0x83c0c07c, '8'},
{0x93c0c06c, '9'},
{0x03c0c0fc, '0'}, //35
{0x41c0c0be, '111'}, //36 //capsLock
{0x26c0c0d9, '222'}, //37 //长按
{0xd0c0c02f, '\n'}
};
public:
char m_name;
DWORD dwFirst;
DWORD dwSecond;
DWORD dwInterval;
源文件:
bool flag;
bool flagletter ;
BOOL CRcsimuDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE);// Set big icon
SetIcon(m_hIcon, FALSE);// Set small icon
irsimu_init( m_hWnd, UM_IR_MESSAGE );
return TRUE;
}
void CRcsimuDlg::OnDestroy()
{
irsimu_exit();
CDialog::OnDestroy();
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CRcsimuDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CRcsimuDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CRcsimuDlg::PreTranslateMessage(MSG* pMsg)
{
switch( pMsg->message )
{
case WM_KEYDOWN:
irsimu_on_keydown( (unsigned char)pMsg->wParam );
flag = true;
break;
case WM_KEYUP:
irsimu_on_keyup( (unsigned char)pMsg->wParam );
flag = false;
break;
}
return CDialog::PreTranslateMessage(pMsg);
}
LRESULT CRcsimuDlg::OnIrMessage( WPARAM wParam, LPARAM lParam )
{
#if 1
CString msg;
static int rows = 0;
dwInterval = 500;
UpdateData( TRUE );
if( 30 < rows++ )
{
rows = 0;
//m_rc_msg.Empty();
}
printf("\r\n");
TRACE("%d\n", rows);
static int cha = 0;
for (int i=0; i<36; i++)
{
//大小写切换
if (wParam == KeyList[36].m_srcName)
{
if (cha == 0)
cha = 'a' - 'A';
else
cha = 0;
//按下capsLock键只是切换字母的大小写状态,而不输入字符
m_name = NULL;
break;
}
//输出字符
if (wParam == KeyList[i].m_srcName)
{
if (i >= 0 && i<= 25)
{
dwFirst = GetTickCount();
m_name = KeyList[i].m_dstName - cha;
break;
}
else if (i>=26 && i<=35)
{
m_name = KeyList[i].m_dstName;
break;
}
}
//屏蔽没有实现的按键:如果按下了其他键,除长按键之外,则赋为空
else if (wParam != KeyList[37].m_srcName)
{
m_name = NULL;
}
//长按持续输出:先出现一个字符,停顿一会,再连续输出。
if (wParam == KeyList[37].m_srcName )
{
dwSecond = GetTickCount();
if (dwSecond - dwFirst < dwInterval)
{
return 0;
}
else
{
break;
}
break;
}
//按Enter键换行
if (wParam == KeyList[38].m_srcName)
{
m_name = KeyList[38].m_dstName;
printf("m_name");
}
}
msg.Format("%c", m_name);
//msg.Format("wParam=%x, lParam=0x%02x key=%c\n", wParam, lParam, m_name );
m_rc_msg += msg;
#else
CString msg;
static int rows = 0;
UpdateData( TRUE );
if( 15 < rows++ )
{
rows = 0;
m_rc_msg.Empty();
}
switch(wParam)
{
case 0x14c0c0eb:
wParam = 'a';
break;
case 0x24c0c0db:
wParam = 'b';
break;
case 0x34c0c0cb:
wParam = 'c';
break;
case 0x44c0c0bb:
wParam = 'd';
break;
case 0x54c0c0ab:
wParam = 'e';
break;
case 0x64c0c09b:
wParam = 'f';
break;
case 0x74c0c08b:
wParam = 'g';
break;
case 0x84c0c07b:
wParam = 'h';
break;
case 0x94c0c06b:
wParam = 'i';
break;
case 0xa4c0c05b:
wParam = 'j';
break;
case 0xb4c0c04b:
wParam = 'k';
break;
case 0xc4c0c03b:
wParam = 'l';
break;
case 0xd4c0c02b:
wParam = 'm';
break;
case 0xe4c0c01b:
wParam = 'n';
break;
case 0xf4c0c00a:
wParam = 'o';
break;
case 0x05c0c0fa:
wParam = 'p';
break;
case 0x15c0c0ea:
wParam = 'q';
break;
case 0x25c0c0da:
wParam = 'r';
break;
case 0x35c0c0ca:
wParam = 's';
break;
case 0x45c0c0ba:
wParam = 't';
break;
case 0x55c0c0aa:
wParam = 'u';
break;
case 0x65c0c09a:
wParam = 'v';
break;
case 0x75c0c08a:
wParam = 'w';
break;
case 0x85c0c07a:
wParam = 'x';
break;
case 0x95c0c06a:
wParam = 'y';
break;
case 0xa5c0c05a:
wParam = 'z';
break;
}
// msg.Format( "wParam=0x%08x, lParam=0x%02x key=%c\n", wParam, lParam, '?' );
msg.Format("wParam=%c, lParam=0x%02x key=%c\n", wParam, lParam, '?');
m_rc_msg += msg;
#endif
UpdateData( FALSE );
return 0;
}
void CRcsimuDlg::OnOK()
{
// TODO: Add your specialized code here an
//d/or call the base class
//CDialog::OnOK();
}