this is a way to monitor the keyboard input. BOOL CApp::MonitorKeyboard() { if ( m_hKbrdThread ) { // close thread hancle wich will terminate the thread // (because I set m_hKbrdThread to NULL) // TerminateThread( m_hKbrdThread ); // terminate thread function is not supported CloseHandle( m_hKbrdThread ); m_hKbrdThread = NULL; m_dwKbrdThreadID = NULL; } // create and start keyboard monitoring thread m_hKbrdThread = CreateThread( NULL, 0, CApp::KeyboardMonitorThread, (LPVOID)this, CREATE_SUSPENDED, &m_dwKbrdThreadID ); if ( m_hKbrdThread == NULL ) return FALSE; // change the thread priority SetThreadPriority( m_hKbrdThread, THREAD_PRIORITY_BELOW_NORMAL ); ResumeThread( m_hKbrdThread ); return TRUE; }....................DWORD CALLBACK CApp::KeyboardMonitorThread( LPVOID lData ) { CApp * pApp = (CApp *)lData; int key_code = 0x41; // save the thread handle when this function is called HTHREAD hThread = pApp->m_hKbrdThread; while( true ) { if ( (GetAsyncKeyState( key_code ) & 0x8000) && (GetAsyncKeyState( VK_MENU ) & 0x8000) ) pApp->OnHotKeyDown(); Sleep( 100 ); // this will kill the thread if ( pApp->m_hKbrdThread != hThread ) break; } // kill the thread. ExitThread(0); return 0; } //and i think mouse hook and keyboard hook can implement this too.
这个是肯定可以实现的.
可以判断消息类型,是鼠标键盘的,就kill.
BOOL CApp::MonitorKeyboard()
{
if ( m_hKbrdThread )
{
// close thread hancle wich will terminate the thread
// (because I set m_hKbrdThread to NULL)
// TerminateThread( m_hKbrdThread ); // terminate thread function is not
supported
CloseHandle( m_hKbrdThread );
m_hKbrdThread = NULL;
m_dwKbrdThreadID = NULL;
}
// create and start keyboard monitoring thread
m_hKbrdThread = CreateThread( NULL, 0, CApp::KeyboardMonitorThread,
(LPVOID)this, CREATE_SUSPENDED, &m_dwKbrdThreadID );
if ( m_hKbrdThread == NULL )
return FALSE;
// change the thread priority
SetThreadPriority( m_hKbrdThread, THREAD_PRIORITY_BELOW_NORMAL );
ResumeThread( m_hKbrdThread );
return TRUE;
}....................DWORD CALLBACK CApp::KeyboardMonitorThread( LPVOID lData )
{
CApp * pApp = (CApp *)lData;
int key_code = 0x41;
// save the thread handle when this function is called
HTHREAD hThread = pApp->m_hKbrdThread;
while( true )
{
if ( (GetAsyncKeyState( key_code ) & 0x8000) && (GetAsyncKeyState(
VK_MENU ) & 0x8000) )
pApp->OnHotKeyDown();
Sleep( 100 );
// this will kill the thread
if ( pApp->m_hKbrdThread != hThread )
break;
}
// kill the thread.
ExitThread(0);
return 0;
}
//and i think mouse hook and keyboard hook can implement this too.
若输入焦点在别的进程的窗口,你的线程能知道么?
不用钩子,除非对所有窗口AttachThreadInput
PLASTINPUTINFO plii // last input event
);
http://www.vckbase.com/vckbase/vckbase6/vc/nonctrls/system_30/0630001.htm