HOOKS.CPP
上传用户:zhang8947
上传日期:2007-01-08
资源大小:1910k
文件大小:20k
- //全程热键
- #include "stdafx.h"
- #include "resource.h"
- #include "systemse.h"
- #include "cspublic.h"
- #include "cskernel.h"
- #include "hooks.h"
- extern HINSTANCE hCsPublic ; //标识该DLL
- CHotKeyParam OHotKeyParam ; //热键参数对象
- static CGetMessageParam OGetMessageParam ; //GETMESSAGE钩子对象
- CHotKeyParam::CHotKeyParam( void )
- {
- m_nHotKeyNum =6 ; //热键数目
- //隐藏或显示浮动条
- m_bCharStatus[0] =1 ; //弹起时有效
- m_fpFunc[0] =(FARPROC)SwitchMainWin ;
- m_bEnable[0] =1 ;
- //隐藏或显示输入板
- m_bCharStatus[1] =1 ;
- m_fpFunc[1] =(FARPROC)SwitchInputBar ;
- if( GetPrivateProfileInt( "输入板参数" ,
- "输入板状态" , 1 , INI_FILE_NAME )==2 ) //禁止中文输入
- m_bEnable[1] =0 ;
- else
- m_bEnable[1] =1 ;
- //取消或启动指取翻译
- m_bCharStatus[2] =1 ;
- m_fpFunc[2] =(FARPROC)SwitchFinger ;
- m_bEnable[2] =1 ;
- //指取翻译辅助键
- m_bCharStatus[3] =0 ;
- m_fpFunc[3] =(FARPROC)AidFinger ;
- if( GetPrivateProfileInt( "指取翻译" , "是否进行指取翻译" ,
- 1 , INI_FILE_NAME ) &&
- GetPrivateProfileInt( "指取翻译" ,
- "是否需要辅助键" , 0 , INI_FILE_NAME ) )
- m_bEnable[3] =1 ;
- else
- m_bEnable[3] =0 ;
- //向后翻页
- m_bCharStatus[4] =0 ;
- m_fpFunc[4] =(FARPROC)PageNext ;
- m_bEnable[4] =0 ;
- //向前翻页
- m_bCharStatus[5] =0 ;
- m_fpFunc[5] =(FARPROC)PagePrior ;
- m_bEnable[5] =0 ;
-
- m_hHookHandle =NULL ;
- m_bActionOk =1 ; //初始动作允许
- m_nHaveDoneKey =-1 ; //初始没有做过动作
- for( int i=0 ; i<MAX_KEYS_NUM ; i++ ) //所有键状态为弹起
- m_bKeysStatus[i] =1 ;
- //从INI文件读取当前热键状态
- //得到当前热键值
- //0为隐藏/显示浮动条热键
- m_bCtrl[0] =GetPrivateProfileInt( "热键参数" ,
- "热键1的Ctrl值" , 0 , INI_FILE_NAME ) ;
- m_bAlt[0] =GetPrivateProfileInt( "热键参数" ,
- "热键1的Alt值" , 1 , INI_FILE_NAME ) ;
- m_bShift[0] =GetPrivateProfileInt( "热键参数" ,
- "热键1的Shift值" , 0 , INI_FILE_NAME ) ;
- m_nChar[0] =GetPrivateProfileInt( "热键参数" ,
- "热键1的Char值" , 59 , INI_FILE_NAME ) ;
- //1为隐藏/显示输入板
- m_bCtrl[1] =GetPrivateProfileInt( "热键参数" ,
- "热键2的Ctrl值" , 1 , INI_FILE_NAME ) ;
- m_bAlt[1] =GetPrivateProfileInt( "热键参数" ,
- "热键2的Alt值" , 0 , INI_FILE_NAME ) ;
- m_bShift[1] =GetPrivateProfileInt( "热键参数" ,
- "热键2的Shift值" , 0 , INI_FILE_NAME ) ;
- m_nChar[1] =GetPrivateProfileInt( "热键参数" ,
- "热键2的Char值" , 0 , INI_FILE_NAME ) ;
- //2为取消/启动屏幕指取翻译
- m_bCtrl[2] =GetPrivateProfileInt( "热键参数" ,
- "热键3的Ctrl值" , 1 , INI_FILE_NAME ) ;
- m_bAlt[2] =GetPrivateProfileInt( "热键参数" ,
- "热键3的Alt值" , 1 , INI_FILE_NAME ) ;
- m_bShift[2] =GetPrivateProfileInt( "热键参数" ,
- "热键3的Shift值" , 0 , INI_FILE_NAME ) ;
- m_nChar[2] =GetPrivateProfileInt( "热键参数" ,
- "热键3的Char值" , 51 , INI_FILE_NAME ) ;
- //3为屏幕指取辅助键
- m_bCtrl[3] =GetPrivateProfileInt( "热键参数" ,
- "热键4的Ctrl值" , 1 , INI_FILE_NAME ) ;
- m_bAlt[3] =GetPrivateProfileInt( "热键参数" ,
- "热键4的Alt值" , 1 , INI_FILE_NAME ) ;
- m_bShift[3] =GetPrivateProfileInt( "热键参数" ,
- "热键4的Shift值" , 0 , INI_FILE_NAME ) ;
- m_nChar[3] =GetPrivateProfileInt( "热键参数" ,
- "热键4的Char值" , 0 , INI_FILE_NAME ) ;
- //4输入法向后翻页
- m_bCtrl[4] =GetPrivateProfileInt( "热键参数" ,
- "热键5的Ctrl值" , 0 , INI_FILE_NAME ) ;
- m_bAlt[4] =GetPrivateProfileInt( "热键参数" ,
- "热键5的Alt值" , 0 , INI_FILE_NAME ) ;
- m_bShift[4] =GetPrivateProfileInt( "热键参数" ,
- "热键5的Shift值" , 0 , INI_FILE_NAME ) ;
- m_nChar[4] =GetPrivateProfileInt( "热键参数" ,
- "热键5的Char值" , 54 , INI_FILE_NAME ) ;
- //5输入法向前翻页
- m_bCtrl[5] =GetPrivateProfileInt( "热键参数" ,
- "热键6的Ctrl值" , 0 , INI_FILE_NAME ) ;
- m_bAlt[5] =GetPrivateProfileInt( "热键参数" ,
- "热键6的Alt值" , 0 , INI_FILE_NAME ) ;
- m_bShift[5] =GetPrivateProfileInt( "热键参数" ,
- "热键6的Shift值" , 0 , INI_FILE_NAME ) ;
- m_nChar[5] =GetPrivateProfileInt( "热键参数" ,
- "热键6的Char值" , 53 , INI_FILE_NAME ) ;
- }
- CHotKeyParam::~CHotKeyParam( void )
- {
- if( m_hHookHandle )
- HookOffHotKey() ;
- }
- void CHotKeyParam::SetEnableFlag( int n , BOOL b )
- {
- if( n<0 || n>=m_nHotKeyNum )
- return ;
-
- m_bEnable[n] =b ;
- }
- CGetMessageParam::CGetMessageParam( void )
- {
- m_hHookHandle =NULL ;
- m_hFocusWnd =NULL ;
- }
- CGetMessageParam::~CGetMessageParam( void )
- {
- if( m_hHookHandle )
- HookOffGetMessage() ;
- }
- //--------------------------------------------------------------------//
- //虚拟键值
- static const WPARAM wVkList[MAX_CHAR_NUM] ={
- 0 , //没有
- VK_ESCAPE ,
- VK_F1 ,
- VK_F2 ,
- VK_F3 ,
- VK_F4 ,
- VK_F5 ,
- VK_F6 ,
- VK_F7 ,
- VK_F8 ,
- VK_F9 ,
- VK_F10 ,
- VK_F11 ,
- VK_F12 ,
- VK_SNAPSHOT ,
- VK_PAUSE ,
- VK_0,VK_1,VK_2,VK_3,VK_4,VK_5,VK_6,VK_7,VK_8,VK_9 ,
- VK_A,VK_B,VK_C,VK_D,VK_E,VK_F,VK_G,VK_H,VK_I,VK_J,
- VK_K,VK_L,VK_M,VK_N,VK_O,VK_P,VK_Q,VK_R,VK_S,VK_T,
- VK_U,VK_V,VK_W,VK_X,VK_Y,VK_Z , //大写字母
- 192 , //`
- 189 , //-
- 187 , //=
- VK_BACK ,
- VK_TAB ,
- 219 , //[
- 221 , //]
- 220 , // ,
- 186 , //;
- 222 , //'
- VK_RETURN ,
- 188 , //,
- 190 , //.
- 191 , // /
- VK_SPACE ,
- VK_INSERT ,
- VK_DELETE ,
- VK_HOME ,
- VK_END ,
- VK_PRIOR ,
- VK_NEXT ,
- VK_LEFT ,
- VK_RIGHT ,
- VK_UP ,
- VK_DOWN
- } ;
- //西文、中文标点对应表,0为奇次按键所对应的中文标点,
- //1为偶次按键所对应的中文标点
- static const BYTE p_bEnChSymbols0[MAX_SYMBOL_NUM] [3]={
- "!" , //!
- "“" , //"
- "#" , //#
- "$" , //$
- "%" , //%
- "§" , //&
- "‘" , //'
- "(" , //(
- "〔" , //)
- "×" , //*
- "+" , //+
- "," , //,
- "-" , //-
- "。" , //.
- "、" , // /,
- "0","1","2","3","4","5","6","7","8","9",
- ":" , //:
- ";" , //;
- "「" , //<
- "=" , //=
- "『" , //>
- "?" , //?
- "℃" , //@
- "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O",
- "P","Q","R","S","T","U","V","W","X","Y","Z",
- "〖" , //[
- "÷" , // ,
- "【" , //]
- "¥" , //^
- "…" , //_
- "·" , //`
- "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o",
- "p","q","r","s","t","u","v","w","x","y","z",
- "《" , //{
- "※" , //|
- "〈" , //}
- "~" } ;
- static const BYTE p_bEnChSymbols1[MAX_SYMBOL_NUM] [3]={
- "!" , //!
- "”" , //"
- "#" , //#
- "$" , //$
- "%" , //%
- "§" , //&
- "’" , //'
- ")" , //(
- "〕" , //)
- "×" , //*
- "+" , //+
- "," , //,
- "-" , //-
- "。" , //.
- "、" , // /,
- "0","1","2","3","4","5","6","7","8","9",
- ":" , //:
- ";" , //;
- "」" , //<
- "=" , //=
- "』" , //>
- "?" , //?
- "℃" , //@
- "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O",
- "P","Q","R","S","T","U","V","W","X","Y","Z",
- "〗" , //[
- "÷" , // ,
- "】" , //]
- "¥" , //^
- "…" , //_
- "·" , //`
- "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o",
- "p","q","r","s","t","u","v","w","x","y","z",
- "》" , //{
- "※" , //|
- "〉" , //}
- "~" } ;
- //标记某键是奇次还是偶次按钮,0为偶,1为奇,初始为0
- static BYTE p_bOddOrEven[MAX_SYMBOL_NUM] ;
- //接口函数
- #ifdef __cplusplus
- extern "C" {
- #endif
- //挂上所有钩子
- BOOL __export FAR PASCAL HookOnAllHooks( void )
- {
- if( !HookOnHotKey() )
- return 0 ;
- if( !HookOnGetMessage() )
- {
- HookOffHotKey() ;
- return 0 ;
- }
- return 1 ;
- }
- //摘掉所有钩子
- void __export FAR PASCAL HookOffAllHooks( void )
- {
- HookOffHotKey() ;
- HookOffGetMessage() ;
- }
- //--------------------------------------------------------------//
- //设置热键值
- void __export FAR PASCAL SetHotKeyParams(
- int n , BOOL bCtrl , BOOL bAlt , BOOL bShift , int nChar )
- {
- if( n<0 || n>=OHotKeyParam.m_nHotKeyNum ) //n不合法
- return ;
-
- OHotKeyParam.m_bCtrl[n] =bCtrl ;
- OHotKeyParam.m_bAlt[n] =bAlt ;
- OHotKeyParam.m_bShift[n] =bShift ;
- OHotKeyParam.m_nChar[n] =nChar ;
- }
- //挂上热键钩子
- BOOL __export FAR PASCAL HookOnHotKey( void )
- {
- OHotKeyParam.m_hHookHandle =SetWindowsHookEx(
- WH_KEYBOARD , HotKeyProc , hCsPublic , NULL ) ;
- if( OHotKeyParam.m_hHookHandle )
- return 1 ;
- return 0 ;
- }
- //摘掉热键钩子
- void __export FAR PASCAL HookOffHotKey( void )
- {
- if( OHotKeyParam.m_hHookHandle )
- {
- UnhookWindowsHookEx( OHotKeyParam.m_hHookHandle ) ;
- OHotKeyParam.m_hHookHandle =0 ;
- }
- }
- //热键钩子函数
- //#define __MYDEBUG
- #ifdef __MYDEBUG
- int nnn=0 ;
- char sBuff[100] ;
- #endif
- LRESULT __export CALLBACK HotKeyProc(
- int code , /* process-message flag */
- WPARAM wParam , /* virtual-key code */
- LPARAM lParam ) /* keyboard-message information */
- {
- if( code < 0 || wParam<0 || wParam>=MAX_KEYS_NUM )
- return CallNextHookEx( OHotKeyParam.m_hHookHandle ,
- code , wParam , lParam ) ;
- //处理热键
- //判断键是松开还是按下
- #ifdef __MYDEBUG
- wsprintf( sBuff , "%d:wParam=%d" , nnn++ , wParam ) ;
- #endif
- if( !(lParam&0x80000000) ) //0为按下
- {
- #ifdef __MYDEBUG
- WritePrivateProfileString( "test" , sBuff , "down" , "test.ini" ) ;
- #endif
- OHotKeyParam.m_bKeysStatus[wParam] =0 ; //标记该键已经按下
- //判断所有的热键
- if( JudgeKeysWhenDown( wParam ) ) //有一个满足要求
- return 1 ; //抛弃这条消息
-
- //-------------------------------------------------------------------------//
- if( GetInputBarStatus() != 1 || //不可以输入中文
- !OHotKeyParam.m_bKeysStatus[VK_CONTROL] ||
- !OHotKeyParam.m_bKeysStatus[VK_MENU] )
- {
- SetMenuCharFlag( 1 ) ; //标记是按钮消失鼠标
- return CallNextHookEx( OHotKeyParam.m_hHookHandle ,
- code , wParam , lParam ) ;
- }
-
- //处理西文、中文标点
- if( !GetInputStatus123(1) ) //是中文标点
- {
- //转换成ASC码
- BYTE n=VKeyToAscii( wParam ,
- OHotKeyParam.m_bKeysStatus[VK_SHIFT] ) ;
- if( n&&
- !( (n>='0'&&n<='9') || (n>='a'&&n<='z') || (n>='A'&&n<='Z') ) )
- {
- char sBuff[3] ;
-
- n -=0x21 ;
- if( p_bOddOrEven[n] ) //偶次
- {
- p_bOddOrEven[n] =0 ;
- strcpy( sBuff , (char*)p_bEnChSymbols1[n] ) ;
- }
- else //奇次
- {
- p_bOddOrEven[n] =1 ;
- strcpy( sBuff , (char*)p_bEnChSymbols0[n] ) ;
- }
- switch( GetInputCode() ) //判断输入内码
- {
- case 1: //BIG5
- ChangeGbToBig5( sBuff , strlen( sBuff ) ) ; //转成BIG5码
- break ;
- case 2: //HZ
- ChangeGbToHz( sBuff , strlen( sBuff ) ) ; //转成HZ
- break ;
- }
- if( SendHz( sBuff ) ) //发送汉字成功
- return 1 ; //抛弃这条消息
- }
- }
- //处理全角、半角字符
- if( !GetInputStatus123(3) ) //是全角字符
- {
- //转换成ASC码
- BYTE n=VKeyToAscii( wParam ,
- OHotKeyParam.m_bKeysStatus[VK_SHIFT] ) ;
- if( n )
- {
- char sBuff[3] ={ 0xa3 , 0 , ' ' } ;
- sBuff[1] =n|0x80 ;
- switch( GetInputCode() ) //判断输入内码
- {
- case 1: //BIG5
- ChangeGbToBig5( sBuff , strlen( sBuff ) ) ; //转成BIG5码
- break ;
- case 2: //HZ
- ChangeGbToHz( sBuff , strlen( sBuff ) ) ; //转成HZ
- break ;
- }
- if( SendHz( sBuff ) ) //发送汉字成功
- return 1 ; //抛弃这条消息
- }
- }
- //处理输入板上字符操作
- if( OHotKeyParam.m_bKeysStatus[VK_SHIFT] ) //没有按下SHIFT键
- {
- if( ::SendMessage( GetInputBarHandle() ,
- WM_USER_INPUT_CHAR , wParam , lParam ) )
- return 1 ; //抛弃这条消息
- }
- SetMenuCharFlag( 1 ) ; //标记是按钮消失鼠标
- }
- else //1为松开某键
- {
- #ifdef __MYDEBUG
- WritePrivateProfileString( "test" , sBuff , "up" , "test.ini" ) ;
- #endif
- HideFinger() ; //松开时,隐藏解释窗口
- if( GetFingerAidedKeyFlag()==2 ) //辅助键按下了
- SetFingerAidedKeyFlag( 1 ) ; //设置没有按下
- //只要松开某键就去掉执行标记
- OHotKeyParam.m_nHaveDoneKey =-1 ;
- //判断所有的热键
- if( JudgeKeysWhenUp( wParam ) ) //有一个满足要求
- {
- OHotKeyParam.m_bActionOk =0 ; //标记动作无效
- OHotKeyParam.m_bKeysStatus[wParam] =1 ; //标记该键没有按下
-
- //判断是否可以取消无效状态
- for( int i=0 ; i<MAX_KEYS_NUM ; i++ )
- if( !OHotKeyParam.m_bKeysStatus[i] ) //该键是按下的
- break ;
-
- if( i==MAX_KEYS_NUM ) //没有按下的键
- OHotKeyParam.m_bActionOk =1 ; //标记有效
-
- return 1 ; //抛弃这条消息
- }
- OHotKeyParam.m_bActionOk =0 ; //标记动作无效
- OHotKeyParam.m_bKeysStatus[wParam] =1 ; //标记该键没有按下
-
- //判断是否可以取消无效状态
- for( int i=0 ; i<MAX_KEYS_NUM ; i++ )
- if( !OHotKeyParam.m_bKeysStatus[i] ) //该键是按下的
- break ;
-
- if( i==MAX_KEYS_NUM ) //没有按下的键
- OHotKeyParam.m_bActionOk =1 ; //标记有效
- }
- return CallNextHookEx( OHotKeyParam.m_hHookHandle ,
- code , wParam , lParam ) ;
- }
-
- //将虚拟键转换成ASC码
- BYTE __export FAR PASCAL VKeyToAscii( WPARAM wParam , BOOL bShiftStatus )
- {
- if( bShiftStatus ) //没有按下SHIFT键
- {
- if( wParam>=VK_0&&wParam<=VK_9 )
- return wParam ;
- if( wParam>=VK_A && wParam<=VK_Z )
- {
- if( GetKeyState( VK_CAPITAL )&1 ) //是大写字母
- return wParam ;
- else
- return( wParam-'A'+'a' ) ; //返回小写字母
- }
- switch( wParam )
- {
- case 192: //`
- return '`' ;
- case 189: //-
- return '-' ;
- case 187: //=
- return '=' ;
- case 219: //[
- return '[' ;
- case 221: //]
- return ']' ;
- case 220: // ,
- return '\' ;
- case 186: //;
- return ';' ;
- case 222: //'
- return ''' ;
- case 188: //,
- return ',' ;
- case 190: //.
- return '.' ;
- case 191: // /
- return '/' ;
- }
- }
- else //按下了SHIFT键
- {
- if( wParam>=VK_A && wParam<=VK_Z )
- {
- if( GetKeyState( VK_CAPITAL )&1 ) //CAPS LOCK键有效
- return( wParam-'A'+'a' ) ; //返回小写字母
- else
- return wParam ;
- }
- switch( wParam )
- {
- case VK_0:
- return ')' ;
- case VK_1:
- return '!' ;
- case VK_2:
- return '@' ;
- case VK_3:
- return '#' ;
- case VK_4:
- return '$' ;
- case VK_5:
- return '%' ;
- case VK_6:
- return '^' ;
- case VK_7:
- return '&' ;
- case VK_8:
- return '*' ;
- case VK_9:
- return '(' ;
- case 192: //`
- return '~' ;
- case 189: //-
- return '_' ;
- case 187: //=
- return '+' ;
- case 219: //[
- return '{' ;
- case 221: //]
- return '}' ;
- case 220: // ,
- return '|' ;
- case 186: //;
- return ':' ;
- case 222: //'
- return '"' ;
- case 188: //,
- return '<' ;
- case 190: //.
- return '>' ;
- case 191: // /
- return '?' ;
- }
- }
-
- return 0 ;
- }
- //当按下某键时,判断是否有符合条件的热键
- BOOL JudgeKeysWhenDown( WPARAM wParam )
- {
- if( OHotKeyParam.m_nHaveDoneKey >-1 ) //已经执行过动作了
- return 0 ; //不再执行了
-
- //判断热键
- for( int i=0 ; i<OHotKeyParam.m_nHotKeyNum ; i++ ) //所有热键
- {
- if( !OHotKeyParam.m_bEnable[i] || //该热键目前无效
- (!OHotKeyParam.m_bCtrl[i] &&
- !OHotKeyParam.m_bAlt[i] &&
- !OHotKeyParam.m_bShift[i] &&
- !OHotKeyParam.m_nChar[i]) ) //该热键没有定义
- continue ;
- if( OHotKeyParam.m_bCharStatus[i] ) //弹起时有效
- {
- #ifdef __MYDEBUG
- wsprintf( sBuff , "%d:i=%d nChar[i]=%d vk=%d" , nnn , i ,
- OHotKeyParam.m_nChar[i],wVkList[OHotKeyParam.m_nChar[i]]) ;
- WritePrivateProfileString( "test" , sBuff , "start" , "test.ini" ) ;
- #endif
- if( OHotKeyParam.m_nChar[i] && //有其它键
- wParam==wVkList[OHotKeyParam.m_nChar[i]] && //是该键
- AllKeysStatusIsOk( i ) ) //所有键状态都正确
- {
- #ifdef __MYDEBUG
- WritePrivateProfileString( "test" , "success" , "ok" , "test.ini" ) ;
- #endif
- (*OHotKeyParam.m_fpFunc[i])() ; //执行该函数
- OHotKeyParam.m_nHaveDoneKey =i ; //做执行过标记
- return 1 ; //成功返回
- }
- continue ; //该热键不符合要求
- }
- else //按下时有效
- {
- if( AllKeysStatusIsOk( i ) ) //所有键状态都正确
- {
- (*OHotKeyParam.m_fpFunc[i])() ; //执行该函数
- // OHotKeyParam.m_nHaveDoneKey =i ; //做执行过标记
- return 1 ; //成功返回
- }
- }
- }
-
- return 0 ; //没有符合要求的热键
- }
-
- //当松开某键时,判断是否有符合条件的热键
- BOOL JudgeKeysWhenUp( WPARAM wParam )
- {
- //判断热键
- for( int i=0 ; i<OHotKeyParam.m_nHotKeyNum ; i++ ) //所有热键
- {
- if( !OHotKeyParam.m_bEnable[i] || //该热键目前无效
- (!OHotKeyParam.m_bCtrl[i] &&
- !OHotKeyParam.m_bAlt[i] &&
- !OHotKeyParam.m_bShift[i] &&
- !OHotKeyParam.m_nChar[i]) ) //该热键没有定义
- continue ;
- if( OHotKeyParam.m_bCharStatus[i] ) //弹起时有效
- {
- if( !OHotKeyParam.m_nChar[i] ) //没有其它键
- {
- //判断是否可能
- if( OHotKeyParam.m_bActionOk && //该动作有效
- AllKeysStatusIsOk( i ) ) //所有键状态都正确
- {
- (*OHotKeyParam.m_fpFunc[i])() ; //执行该函数
- return 1 ; //成功返回
- }
- }
- }
- }
- return 0 ; //没有符合要求的热键
- }
- //判断是否所有键的状态都符合要求
- BOOL AllKeysStatusIsOk( int n )
- {
- //所有键的状态都要符合
- for( int i=0 ; i<MAX_KEYS_NUM ; i++ )
- {
- #ifdef __MYDEBUG
- wsprintf( sBuff , "%d:i=%d" , nnn , i ) ;
- WritePrivateProfileString( "test" , sBuff , "checkkey" , "test.ini" ) ;
- #endif
- if( i==VK_CONTROL ) //是Ctrl键
- {
- if( OHotKeyParam.m_bKeysStatus[i]==
- OHotKeyParam.m_bCtrl[n] ) //状态不符
- return 0 ;
- continue ; //状态相符
- }
- if( i==VK_MENU ) //是Alt键
- {
- if( OHotKeyParam.m_bKeysStatus[i]==
- OHotKeyParam.m_bAlt[n] ) //状态不符
- return 0 ;
- continue ; //状态相符
- }
- if( i==VK_SHIFT ) //是Shift键
- {
- if( OHotKeyParam.m_bKeysStatus[i]==
- OHotKeyParam.m_bShift[n] ) //状态不符
- return 0;
- continue ; //状态相符
- }
- if( OHotKeyParam.m_nChar[n] ) //需要其它键
- {
- if( (WPARAM)i==wVkList[OHotKeyParam.m_nChar[n]] ) //是该键
- {
- if( OHotKeyParam.m_bKeysStatus[i] ) //该键没有按下
- return 0 ;
- continue ; //该键按下了
- }
- }
- //不是其中某键者不能按下
- if( !OHotKeyParam.m_bKeysStatus[i] ) //按下了
- return 0 ;
- }
-
- return 1 ; //都符合状态
- }
- //切换指取翻译
- extern "C" void __export FAR PASCAL SwitchFinger( void )
- {
- if( GetFingerTranslate() ) //当前是可以进行指取翻译的
- {
- SetFingerTranslate( 0 ) ; //设成不可以
- HookFingerOff() ; //卸掉指取模块
-
- if( GetOutputCode()==5 ) //当前不显示汉字
- ToEnglish() ; //卸掉汉字系统
- OHotKeyParam.m_bEnable[3] =0 ; //辅助键无效
- }
- else
- {
- if( GetOutputCode()==5 ) //当前不显示汉字
- ToChinese() ; //挂上汉字系统
-
- if( GetFingerAidedKeyFlag() ) //需要辅助键
- OHotKeyParam.m_bEnable[3] =1 ; //辅助键有效
- SetFingerTranslate( 1 ) ; //设成可以
- HookFingerOn() ; //挂上指取模块
- StartFingerTranslation() ; //开始指取翻译
- }
- }
- //指取翻译辅助键
- void AidFinger( void )
- {
- SetFingerAidedKeyFlag( 2 ) ; //标记辅助键已经按下
- StartFingerTranslation() ; //开始指取翻译
- }
- //输入法向后翻页
- void PageNext( void )
- {
- ::SendMessage( GetInputBarHandle() , WM_USER_SCROLL_PAGE ,
- 3 , 0 ) ;
- }
- //输入法向前翻页
- void PagePrior( void )
- {
- ::SendMessage( GetInputBarHandle() , WM_USER_SCROLL_PAGE ,
- 4 , 0 ) ;
- }
- //----------------------------------------------------------------------------------//
- //WH_GETMESSAGE 钩子函数对象
- //挂上WH_GETMESSAGE钩子
- BOOL __export FAR PASCAL HookOnGetMessage( void )
- {
- OGetMessageParam.m_hHookHandle =SetWindowsHookEx(
- WH_GETMESSAGE , GetMessageProc , hCsPublic , NULL ) ;
- if( OGetMessageParam.m_hHookHandle )
- return 1 ;
- return 0 ;
- }
- //摘掉WH_GETMESSAGE钩子
- void __export FAR PASCAL HookOffGetMessage( void )
- {
- if( OGetMessageParam.m_hHookHandle )
- {
- UnhookWindowsHookEx( OGetMessageParam.m_hHookHandle ) ;
- OGetMessageParam.m_hHookHandle =0 ;
- }
- }
- //得到当前拥有输入焦点的窗口句柄
- HWND __export FAR PASCAL GetFocus32( void )
- {
- return OGetMessageParam.m_hFocusWnd ;
- }
- //WH_GETMESSAGE钩子函数
- LRESULT __export CALLBACK GetMessageProc(
- int code , /* process-message flag */
- WPARAM wParam , /* undefined */
- LPARAM lParam ) /* pointer to MSG structure */
- {
- if( code>=0 )
- {
- HWND hActiveWnd = ::GetActiveWindow(); //当前活动窗口
- if( ((MSG*)lParam)->hwnd == hActiveWnd || //是活动窗口
- IsChild( hActiveWnd , ((MSG*)lParam)->hwnd) ) //或是活动窗口的子窗口
- {
- OGetMessageParam.m_hFocusWnd =::GetFocus() ;
- /* HWND hWnd = ::GetFocus(); // Get Current Focus Window
- if( hWnd )
- OGetMessageParam.m_hFocusWnd =hWnd ;
- else //为空
- {
- if( !IsChild(hActiveWnd, hFocusWnd)) //不是其子窗口
- hFocusWnd =hWnd;
- }
- */
- }
-
- if( ((MSG*)lParam)->message == WM_LBUTTONDBLCLK )
- SetMenuCharFlag( 1 ) ; //标记为同按键消失菜单
- }
-
- return CallNextHookEx( OGetMessageParam.m_hHookHandle,
- code, wParam, lParam ) ;
- }
- //设置翻页按钮的有效性,1有效,0无效
- void __export FAR PASCAL SetScrollPageKeysStatus( BOOL bLeft ,
- BOOL bRight )
- {
- OHotKeyParam.m_bEnable[4] =bRight ;
- OHotKeyParam.m_bEnable[5] =bLeft ;
- }
- #ifdef __cplusplus
- }
- #endif