软件功能:
按enter或者ctrl+enter 点击指定图片
我是打联盟用的,上个厕所回来,正好匹配到,突然帕金森,可能来不及点接受,所以做了一个这个,吐槽一下,接受必须用鼠标点是挺麻烦的
涉及知识点(大佬请无视):
1 管理员权限打开 在代码第一行加上
//RUNAS//
2 原子窗口,避免应用被重复打开
3 托盘图标实现 来自前辈的代码(https://bbs.aardio.com/forum.php?mod=viewthread&tid=10257)
4 热键注册
5 监听关闭操作
6 截图与识图
源码:
//RUNAS//
//系统热键
import win.ui;
import win.ui.atom;
var appName="SuperEnter";
/*DSG{{*/
var winform = win.form(text=appName;right=223;bottom=143;max=false;min=false;parent=...)
winform.add(
picturebox={cls="picturebox";left=56;top=72;right=144;bottom=120;notify=1;z=4};
radiobutton={cls="radiobutton";text="Enter";left=48;top=24;right=128;bottom=48;z=1};
radiobutton2={cls="radiobutton";text="Ctrl+Enter";left=128;top=24;right=224;bottom=48;checked=1;z=2};
static={cls="static";text="点此截取图片";left=56;top=88;right=136;bottom=120;transparent=1;z=3}
)
/*}}*/
//原子窗口避免重复打开
var atom,hwnd/*冲突窗口的句柄,该函数会自动激活此窗口*/ = winform.atom("SuperEnter");
if(!atom){
/*为窗口设置原子值可以避免一个程序重复运行多个实例*/
win.quitMessage(); return;
}
import win.util.tray;
var tray = win.util.tray(winform,$"\res\1.ico") //创建托盘图标,如果不能显示图标,可能是图标问题,要复合图标
tray.message = 0x400+9981/*_WM_TRAYMESSAGE*/
tray.tip = appName //设置鼠标提示
winform.onClose = function(hwnd,message,wParam,lParam){
tray.delete(); //关闭窗口同时删掉托盘,避免关闭窗口后要鼠标移到托盘图标才消失
}
//下面是添加托盘右键菜单
import win.ui.menu;
winform.popmenu=win.ui.popmenu(winform);
winform.popmenu.add('打开',function(id){ //添加了一个打开主界面的菜单
winform.show();
})
winform.popmenu.add('退出',function(id){ //添加了一个退出程序的菜单
//winform.close()
win.quitMessage()
})
//关闭按钮改为最小化
winform.wndproc = function(hwnd,message,wParam,lParam){
select( message ) {
case 0x10/*_WM_CLOSE*/{
::PostMessage(winform.hwnd, 0x112/*_WM_SYSCOMMAND*/,0xF020/*_SC_MINIMIZE*/, 0);
return 1;
}
else{
}
} //无返回值则继续调用默认回调函数
}
//下面是获取鼠标消息弹出上面的右键菜单
import mouse;
winform.wndproc = function(hwnd,message,wparam,lparam){
select(message) {//判断消息类型
case( 0x400+9981/*_WM_TRAYMESSAGE*/ ) { //托盘图标消息
if(lparam = 0x203/*_WM_LBUTTONDBLCLK)*/){ //鼠标双击
winform.show(true);
}
elseif(lparam =0x205/*_WM_RBUTTONUP*/){ //鼠标右键
x,y = mouse.getPos();
win.setForeground(winform.hwnd)
winform.popmenu.popup(x,y,true)
}
}
case( 0x112/*_WM_SYSCOMMAND*/ ){ //系统命令消息
if( wparam == 0xF020/*_SC_MINIMIZE*/ ){ //用户点击了最小化按钮
winform.show(false); //隐藏窗口
return true;//阻击默认消息传递,取消最小化过程
}
}
}
}
winform.picturebox.image="/test.jpg";
var hkId;
import mouse;
import soImage;//导入搜图扩展库
import soImage.directX;
import console;
function func(){
winform.show(0/*_SW_MINIMIZE*/);
sleep(100)
var dxSnap = soImage.directX();
var imgFind = soImage();
imgFind.load("/test.jpg");
var sm,x,y=imgFind.findImage(dxSnap.captureToImage());
if(sm<80){
win.msgbox("没找到该图片");
}else{
mouse.moveTo(x,y,true,100,10);
sleep(10);
mouse.click();
//点击完移动位置避免影响下次识别
var mx,my=mouse.getPos();
mouse.moveTo(mx+50,my+50,true,100,10);
}
}
function bindEnter(ctrl){
if(ctrl==1){
ctrl=2/*_VK_CTRL*/;
}else{
ctrl=null;
}
winform.unreghotkey(hkId);
//重新注册系统热键;
hkId = winform.reghotkey(
function(id,mod,vk){
func();
}
//winform.hotkey.gethotkey()刚好返回2个值对应最后两个参数
,ctrl,0xD/*_VK_ENTER*/
);
}
winform.radiobutton.oncommand = function(id,event){
bindEnter(0);
}
winform.radiobutton2.oncommand = function(id,event){
bindEnter(1);
}
if(winform.radiobutton.checked){
bindEnter(0);
}elseif(winform.radiobutton2.checked){
bindEnter(1);
}
//截屏选区
import mouse.screenArea;
winform.picturebox.oncommand = function(id,event){
var screenArea = mouse.screenArea();
screenArea.onSelectionChanged = function(rc){
import gdip.snap;
var bmp = gdip.snap(screenArea.hwnd,rc.xywh());
bmp.save("/test.jpg",100);
owner.close();
}
screenArea.doModal();
winform.picturebox.image="/test.jpg";
}
winform.enableDpiScaling();
winform.show();
win.loopMessage();
附件是打包好的exe和源码