import win.ui;
/*DSG{{*/
var winform = win.form(text="鼠标钩子演示 - 请按下鼠标键测试";right=438;bottom=396;max=false;parent=...;topmost=1)
winform.add(
edit={cls="edit";left=13;top=12;right=426;bottom=382;edge=1;multiline=1;z=1}
)
/*}}*/

import mouse.hook;
var hook = mouse.hook();

//录制回调函数
hook.proc = function(msg,x,y,mouseData,injected,flags,timeStamp,extraInfo){
	if( injected ) return; //模拟鼠标不处理
  
    select(msg) {
    	case 0x201/*_WM_LBUTTONDOWN*/{
    	    winform.edit.print("左键按下",x,y)
    	}
    	case 0x202/*_WM_LBUTTONUP*/{
    	    winform.edit.print("左键弹起",x,y)
    	}
    	case 0x204/*_WM_RBUTTONDOWN*/{
    	    winform.edit.print("右键按下",x,y)
    	}
    	case 0x205/*_WM_RBUTTONUP*/{
    	    winform.edit.print("右键弹起",x,y)
    	}
        case 0x207/*_WM_MBUTTONDOWN*/{
    	    winform.edit.print("中键按下",x,y)
    	}
    	case 0x208/*_WM_MBUTTONUP*/{
    	    winform.edit.print("中键弹起",x,y) 
    	}   
    }   
} 

winform.wndproc = function(hwnd,message,wparam,lparam){ 
    if( message = 0xA1/*_WM_NCLBUTTONDOWN*/ ){
        if( wparam == 20/*_HTCLOSE*/ ){ 
        	//鼠标按下关闭按钮、释放鼠标以前及时关闭钩子,避免 XP 系统关闭窗体时出现的卡顿
            hook.close() 
        }
    }  
}  
  
winform.show(true) 
win.loopMessage();  