当前位置: 首页 > 工具软件 > SmartInvoke > 使用案例 >

通过SmartInvoke运用java与flex轻松构建cs程序(捕获鼠标键盘事件)

百里承业
2023-12-01

 通过实现flashPlayer activeX的消息钩子可以很轻松的屏蔽掉flex的系统右键菜单, 从而实现自己的右键菜单。当然这个消息钩子也会监听到键盘消息,从而你可以很轻松 的实现自己的键盘事件。 代码如下:

  1.    //将flash控件添加到窗体   
  2. this .flashContainer= new  FlashContainer( this );  
  3. //添加消息钩子   
  4. this .flashContainer.addHookInterceptor( new  OleHookInterceptor(){  
  5.     /**如果此方法返回false表示不过滤此消息。返回true表示消息被过滤掉了,那么  
  6.      *flashPlayer就接收不到相应的消息事件,也就实现了屏蔽系统右键菜单与自定义  
  7.      *键盘事件的目的  
  8.      */   
  9.     public   boolean  intercept(Msg message,  int  code,  int  wParam,  
  10.             int  lParam) {  
  11.         int  msg=message.getMessage();  
  12.         if  (msg== Win32Constant.WM_RBUTTONDOWN) { //系统右键消息   
  13.               
  14.             Point cursor = flashContainer.getParent().toControl(  
  15.                     Display.getCurrent().getCursorLocation());  
  16.             //如果当前鼠标在flashPlayer窗口中   
  17.             if  (flashContainer.getBounds().contains(cursor) && flashContainer.isVisible()) {  
  18.                 //显示一消息对话框   
  19.                 MessageBox messageBox = new  MessageBox(flashContainer  
  20.                         .getShell());  
  21.                 messageBox.setMessage("您单机了右键" );  
  22.                 messageBox.open();  
  23.                 return   true ; //返回true就屏蔽了flashPlayer的系统右键   
  24.             }  
  25.               
  26.         }  
  27.         if (msg==Win32Constant.WM_KEYDOWN){ //键盘按键按下事件   
  28.             System.out.println("按下" +( char )message.getWParam());  
  29.         }  
  30.         //以下的代码可以捕获到键盘组合键   
  31.         if ((OS.GetKeyState(Win32Constant.VK_CONTROL)< 0 )&&(OS.GetKeyState(Win32Constant.VK_DELETE)< 0 )&&(message.getWParam()   ==    'Z' )){  
  32.             System.out.println("control DELETE and Z..........." );  
  33.         }  
  34.         return   false ;  
  35.     }  
  36. }); 
下载 http://smartinvoke.cn/
 类似资料: