StrokesPlus.net教程及脚本持续更新

正如为S+net提供中文翻译的小恐龙大佬提到:

属于一开始要折腾,但是之后会非常牛逼的类型

分享一些接触到的手势脚本,一些简单案例,一些基础设置,部分取自已经发在卡饭的帖子、官方论坛,其中,案例分为可修改动作使用,和方法对应成品

脚本打包配置文件(从Strokesplusnet v0.5.6.3导出)见下方,直接导入使用,可勾选需要的功能,其中,选项如果不需要可以取消勾选,部分脚本未设置手势,导入不会覆盖已设置手势(左键点击和启动/退出脚本不确定会不会覆盖)

  • 软件介绍

         推荐一个手势软件strokesplus.net

  • 软件官网

         https://www.strokesplus.net

  • 脚本存放Github

         GitHub - lyscop/Strokesplus.Net-Scripts

  • 脚本打包配置文件

         StrokesPlus.net-2022-02-19-230431.zip - 蓝奏云

  • 手势图

         a. 参照分享Strokesplus脚本MAX大佬分区域的手势图,用画图制作的手势图,供参考

        a5Z4OO
         b. 已经将部分功能转到了右键菜单,再转成了弹图标栏

  • 更新

         20220807 10. 划词翻译 v0.3 22# 修复划词英文非单词报错
         20220414 10. 划词翻译 v0.2 22# 从json中获取翻译结果
         20220321 2. 截图显示屏幕(调用win10截图快捷键)3# |(手势框选区域)4# 19. 选中图
                             片预览 v1.2 14# 更新双击关闭/预览关闭后,清除S+内存 ,由于增加S+内存
                             占用,当前方法是转移到虚拟内存,暂时不要使用
         20220305 7. 解压缩到当前文件夹(7Zip)修复压缩包内有文件夹,命令行显示没有文件
                             夹不能解压的问题 10#
         20220219 19. 选中图片预览 v1.1 修复桌面显示图片预览后,只能双击预览关闭 14#

  • 添加

         20220805 案例24. 弹图标栏 63#
                          类似Mac OS上的PopClip以及Windows上的SnipDo(原Pantherbar),弹
                          出图标栏,通过图标替代右键菜单文字显示,鼠标移动到图标显示提示,点击图
                          标执行动作,比如启动指定软件、复制、粘贴、剪切文字、打开链接等等
        a5Z4OO
         20220320 案例5. 定时执行动作/启动程序 35#
                          案例4. 最小化到托盘、最小化指定窗口到托盘(指定窗口设置老板键)34#
                          案例3. 屏幕边缘滚动调节亮度、声音、浏览器标签页切换、程序切换 33#
         20220314 成品23. 桌面显示倒计时 36#

  • 第一部分成品

         1. 自动6s关闭大写 2#
         2. 截图显示屏幕(调用win10截图快捷键)3# |(手势框选区域)4#
         3. 截图OCR(调用win10截图快捷键 百度OCR api)5#
         4. 截图保存桌面(调用win10截图快捷键)6#
         5. 桌面提示中英文输入法状态(搜狗)/ 大写提示 7#

        a5Z4OO
         6. 设置当前输入法为中文或者英文(搜狗)8#
             需要在启动/退出-启动(开启)中添加 7# 第一部分代码
         7. 解压缩到当前文件夹(7Zip)10#
             分别解压缩包内单文件、单文件夹、多文件文件夹、批量解压缩,需要含密码情况留言
         8. 压缩选中文件、文件夹(7Zip)9#
             分别压缩选中单文件、单文件夹、多文件文件夹
         9. 鼠标穿屏 11#
             鼠标在屏幕上下左右边界穿过到另一侧,如果使用多个屏幕需要调整代码
         10. 划词翻译 v0.2 22#
             划词后,中文Google翻译,英文句子Google翻译,英文单词有道翻译,结果保存剪
             切板,同时显示在鼠标处
             自动6秒关闭结果显示,鼠标点击和滚动关闭显示需要在鼠标事件中设置
             
        a5Z4OO
         11. 选中图片上传返回链接(ShareX) 23#
               自带图床有(Imgur、vgy等),自定义上传图床(Imgbb无法外链大图),可添加工作
               流上传后Google搜索
         12. 选中图片打开编辑(ShareX)24#
               使用命令行,跳过弹出点击选择窗口
         13. Alt+拖动窗口 25#
         14. 搜索选中文字或打开链接 26#
         15. 固定鼠标在屏幕的当前点 30#
               用于鼠标1分钟未移动,固定当前点,避免鼠标误移动到角落执行动作
         16. 屏幕取色 27#
         17. 当前窗口信息 28#
         18. 选中图片转化base64 29#
         19. 选中图片预览(更新 v1.1) 14#
               资源管理器、桌面选中图片后,直接在鼠标处显示预览,点击空白处关闭预览,和双击
               左键关闭(用于切换其他窗口,预览未关闭情况),鼠标拖动,滚动放大缩小,选中下
               一张图片继续预览(所选图片来自网络,侵权联系删除)

        a5Z4OO
         20. 右键执行中键 31#
               点右键关闭浏览器标签页,打开书签栏书签,支持Chrome,Edge,Firefox,按
               Ctrl+右键正常显示菜单,不过还是手势关闭比较方便
         21. WEBP互转JPG、PNG、BMP
         22. 窗口透明(鼠标可点击) 32#
               执行后鼠标所在窗口透明,且置顶,鼠标可点击后方窗口,再次执行后恢复
         23. 桌面显示倒计时 36#
               输入结束时间,倒计时显示桌面,结束后发出嘀声
               时间格式为年, 月, 日, 时, 分(可选), 秒(可选) 或者 年-月-日-时-分(可选)-秒(可选)

        a5Z4OO

  • 第二部分案例

         1. 任意窗口搜索输入内容 12#
             类似于 Power Toys 或者 Listary

        a5Z4OO
         2. 光标移动到屏幕角落执行动作 13#
             鼠标停留在角落执行动作,鼠标移出再移入,取消执行动作
         3. 屏幕边缘滚动调节亮度、声音、浏览器标签页切换、程序切换 33#
         4. 最小化到托盘、最小化指定窗口到托盘(指定窗口设置老板键) 34#
         5. 定时执行动作/启动程序 35#
         6. 监控设备接入
         7. 监控程序启动/退出
         8. 全局手势中指定不同程序
         9. 指定软件设置快捷键
         10. 手势作用在浏览器特定的页面
         11. 双击鼠标左键/右键/中键
         12. 双击Ctrl/Alt
         13. 请求HTTPS
         14. 当前时间格式
         15. 桌面/文件夹所有文件数文件名、文件文件夹数量、选中桌面/文件夹文件
         16. 内置函数信息
         17. 调整窗口尺寸位置
         18. 忽略软件/区域、全屏禁用手势
         19. 更换触发鼠标键
         20. 窗口、图片放大缩小
         21. 窗口置前、置顶
         22. 手势对应热键识别窗口
         23. 调用 .NET API函数
         24. 弹图标栏 63#
               类似Mac OS上的PopClip以及Windows上的SnipDo(原Pantherbar),弹
               出图标栏,通过图标替代右键菜单文字显示,鼠标移动到图标显示提示,点击图
               标执行动作,比如启动指定软件、复制、粘贴、剪切文字、打开链接等等

  • 第三部分设置

         1. 统计手势次数
         2. 应用程序定义
         3. 切换语言

7 Likes

自动6s关闭大写

搜狗、微软输入法等

方法1

添加到热键-脚本,热键设置CAPITAL(大写锁定键),勾选激活、不注册


sp.DeleteTimer('Capsclose');
sp.DisplayTextClose();
var info = new DisplayTextInfo();
info.TitleFont = new Font('Segoe UI', 12, host.flags(FontStyle.Bold));
info.MessageFont = new Font("Segoe UI Semibold", 10);
info.ForeColor = "255,255,255";
info.Duration = 1000;
info.Location = "bottomleft";
info.Padding = 10;

if (sp.IsKeyToggled(vk.CAPITAL)) {
    info.BackColor = "37,146,52";
    info.Message = "CAPS Lock is ON";
    sp.DisplayText(info);

    //6秒后自动关闭Caps,不需要可以注释掉或者删除
    sp.CreateTimer('Capsclose', 6000, 0,
        `if (sp.IsKeyToggled(vk.CAPITAL)) {
            var info = new DisplayTextInfo();
            info.TitleFont = new Font('Segoe UI', 12, host.flags(FontStyle.Bold));
            info.MessageFont = new Font("Segoe UI Semibold", 10);
            info.BackColor = "37,146,52";
            info.BackColor = "200,56,70";
            info.Message = "CAPS Lock is OFF";
            info.Duration = 1000;
            info.Location = "bottomleft";
            info.Padding = 10;
            sp.DisplayText(info);
            sp.SendVKey(vk.CAPITAL);
        }`);

} else {
    info.BackColor = "200,56,70";
    info.Message = "CAPS Lock is OFF";

    sp.DisplayText(info);
}

方法2

添加到全局动作-启动/退出-启动(开启)

重要设置:选项-高级-启动订阅键盘钩子事件

if(__spEngineWrapper.Engine.Name == sp.EngineList().Last().Engine.Name) {
     var keyboardEventObj = sp.GetStoredObject("keyboardEvent");
     if(!keyboardEventObj.GetType().FullName.includes('EventConnection')) {
         //Bind to the synchronous event
         var keyboardEvent = KeyboardHook.OnKeyboardHookEventAsync.connect(
             function (sender, keyboardHookEvent) {
                 //Wrap all code in try/catch, exceptions will crash S+, such as calling clip.SetText with a null value
                 try {
                     if(keyboardHookEvent.Key == vk.CAPITAL) {
                        if(keyboardHookEvent.KeyState == KeyState.Up) {
                            if(!sp.GetStoredBool("CAPSOn")) {
                                sp.StoreBool("CAPSOn", true); 
                                sp.CreateTimer('Capsclose', 6000,  0, `sp.SendVKey(vk.CAPITAL); sp.DeleteTimer('Capsclose');  `);
                            } else {
                                sp.StoreBool("CAPSOn", false); 
                                sp.DeleteTimer('Capsclose');
                            }
                        }
                    }
                }
                catch {}
            });
        sp.StoreObject("keyboardEvent", keyboardEvent);
    }
}

截图显示屏幕(调用win10截图快捷键)

手势截图后显示在屏幕上,双击关闭、滚轮放大缩小、右键保存

可设置右键后弹出选项、右键后弹出文件夹、右键直接保存到指定目录,如有需要留言

默认同时只能截图2个,需要同时截图多个,选项-脚本-最大脚本池容量改成20

S+net已内置显示剪切板图片到桌面的方法
//sp.DisplayImage(clip.GetImage(), true);

先添加38#代码

再添加到动作

var startimage = clip.GetImage();

sp.SendModifiedVKeys([vk.LSHIFT,vk.LWIN], [vk.VK_S]);

sp.Sleep(10);//延时进入截图界面时间
for(i=0; i< 6000; i++) {
    //ScreenClippingHost
    sp.Sleep(1000);
    var wnd = sp.WindowsFromTitlePartial("屏幕截图");
    
    if(i > 0 && wnd.Count() === 0 && clip.ContainsImage()) {


        sp.Sleep(1500);

            ShowImage(clip.GetImage(), action.End, 1);
            //sp.DisplayImage(clip.GetImage(), true); 
            //ImageWithMenu.Show(clip.GetImage(), action.Start, 1);//0 顶部白框

            function ShowImage(img, pt, border) {
                if (img == null) return;

                var Forms = forms.System.Windows.Forms;
                if (border == null) border = 0;
                if (border != 0) { pt = new Point(pt.X - border, pt.Y - border); }

                var form = new Forms.Form;
                form.StartPosition = Forms.FormStartPosition.Manual;
                form.FormBorderStyle = (border != 0) ? //border != 0顶部白框
                    Forms.FormBorderStyle.None :
                    Forms.FormBorderStyle.SizableToolWindow ;
                form.TopMost = true;
                form.ControlBox = false;
                form.ShowInTaskbar = false;
                form.Margin = new Forms.Padding(0);
                if (border != 0) { form.Padding = new Forms.Padding(border); }
                form.MinimumSize = new Size(10, 10);
                form.Size = new Size(10, 10);
                form.Location = pt;
                form.AutoSize = true;
                form.GetType().GetProperty("DoubleBuffered",
                    host.flags(clr.System.Reflection.BindingFlags.NonPublic,
                    clr.System.Reflection.BindingFlags.Instance))
                    .SetValue(form, true);
                form.BackColor = drawing.System.Drawing.SystemColors.HotTrack;//蓝线 白线

                //透明边框
                //form.BackColor = Color.LimeGreen;
                //form.TransparencyKey = Color.LimeGreen;

                var pic = new Forms.PictureBox;
                pic.Name = 'pic';
                pic.SizeMode = Forms.PictureBoxSizeMode.Zoom;
                pic.Size = new Size(img.Width, img.Height);
                pic.BackColor = drawing.System.Drawing.SystemColors.Control;
                if (border != 0) { pic.Location = new Point(border, border); }
                pic.Image = img;

                form.Controls.Add(pic);
                var autoSize = form.Size;
                var t = (form.ClientSize.Width - pic.Width - form.Padding.Horizontal);
                autoSize.Width -= t;
                autoSize.Height -= t;
                form.AutoSize = false;
                form.Size = autoSize;
                pic.Dock = Forms.DockStyle.Fill;

                var form_shown = 
                form.Shown.connect(
                function (sender, args) {
                    form.TopMost = true;
                    form.Activate();
                });

                //左键双击关闭贴图
                var pic_doubleClick = 
                pic.DoubleClick.connect(
                function (sender, args) {
                    var currentMouseLocation = sp.GetCurrentMousePoint();
                    form.Close();  
                    FlushMemory();
                });


                //右键选项
                menuBlind = ShowImageBindAllMenu(form, pic);

                dragMoveBlind = ShowImageBindDragMove(form, pic);
                wheelResizeBlind = ShowImageBindWheelResize(form, pic);


                Forms.Application.Run(form);
            }

            function ShowImageBindWheelResize(form, pic) {
                var form_mouseWheel = 
                form.MouseWheel.connect(
                function (sender, e) {
                    var factor = e.Delta / 1000;
                    var ampt = forms.System.Windows.Forms.Control.MousePosition;
                    var rmpt = new Point();
                    rmpt.X = ampt.X - form.Left;
                    rmpt.Y = ampt.Y - form.Top;
                    var intFunc = Math.floor;
                    rmpt.X +=  intFunc(rmpt.X * factor);
                    rmpt.Y +=  intFunc(rmpt.Y * factor);
                    form.SetBounds(ampt.X - rmpt.X, ampt.Y - rmpt.Y, 
                    form.Width + intFunc(form.Width *  factor), 
                    form.Height + intFunc(form.Height *  factor));
                });
                return [form_mouseWheel];
            }
            function ShowImageBindAllMenu(form, pic) {
                var Forms = forms.System.Windows.Forms;

                var contextMenu1 = new Forms.ContextMenu();
                var menu1 = contextMenu1.MenuItems.Add("Save File");

                // item 1
                var saveFileDialog1  = new Forms.SaveFileDialog();
                saveFileDialog1.Filter = "png files (*.png)|*.png" ;
                saveFileDialog1.RestoreDirectory = true ;
                //saveFileDialog1.FileName = clr.System.DateTime.Now.ToString().replace(/[/\*?":<>| ]/g, '_');

                var d = new Date();
                saveFileDialog1.FileName  = "image-"+d.getFullYear()
                                                 + "-"
                                                 + ("0" + (d.getMonth()+1)).slice(-2)
                                                 + "-"
                                                 + ("0" + d.getDate()).slice(-2)
                                                 + " "
                                                 + ("0" + d.getHours()).slice(-2) 
                                                 +  "" 
                                                 + ("0" + d.getMinutes()).slice(-2)
                                                 +  "" 
                                                 + ("0" + d.getSeconds()).slice(-2);

                var menu1_click  = menu1.Click.connect(function (sender, e) {
                    if (saveFileDialog1.ShowDialog() == Forms.DialogResult.OK) {
                        pic.Image.Save(saveFileDialog1.FileName, drawing.System.Drawing.Imaging.ImageFormat.Png);
                    }
                });
                pic.ContextMenu = contextMenu1;
                return [menu1_click];
            }
            function ShowImageBindDragMove(form, pic) {
                var Cursors = forms.System.Windows.Forms.Cursors;
                var ReleaseCapture = sp_config.GetType().Assembly.GetType("API").GetMethod("ReleaseCapture");

                var pic_mouseMove = 
                pic.MouseMove.connect(
                function (sender, e) {
                    var hitResize = form.Height + form.Width - (e.X + e.Y) < 30;
                    var cursor = hitResize ? Cursors.SizeNWSE : Cursors.Default;
                    if (pic.Cursor != cursor) pic.Cursor = cursor;
                    if (e.Button == MouseButtons.Left) {
                        ReleaseCapture.Invoke(null, null);
                        sp.WindowFromHandle(form.Handle).SendMessageObj(0x0112,
                            hitResize ? 0xF008 : 0xF012, 0);
                    }
                });

                return [pic_mouseMove];
            }
        break;
    }
}

        function FlushMemory()
        {
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
            if (System.Environment.OSVersion.Platform == System.PlatformID.Win32NT)
                NativeModules.Kernel32.SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
        } 
                

手势截图后显示在屏幕上,双击关闭、滚轮放大缩小、右键保存

默认同时只能截图2个,需要同时截图多个,选项-脚本-最大脚本池容量改成20

先添加38#代码

再将以下代码设置到一个正方形手势中

// Copies the area within the square gesture area to the clipboard, like a screenshot

//Delay to ensure S+ has cleared the gesture and hint
sp.Sleep(100); 
//Create a new Bitmap in memory
var memoryImage = new drawing.System.Drawing.Bitmap(action.Bounds.Width, action.Bounds.Height);
//Create a graphics object associated with the bitmap
var memoryGraphics = drawing.System.Drawing.Graphics.FromImage(memoryImage);
//Copy the screen within the bounding rectangle of the drawn gesture area
//I used a square gesture since that seems more intuitive, but it's not neccessary
memoryGraphics.CopyFromScreen(action.Bounds.X, action.Bounds.Y, 0, 0, action.Bounds.Size);
//Copy the image to the clipboard
clip.SetImage(memoryImage);
memoryGraphics.Dispose();
memoryImage.Dispose();

//sp.DisplayImage(clip.GetImage(), true);
ShowImage(clip.GetImage(), action.End,1);
//ImageWithMenu.Show(clip.GetImage(), action.Start, 1);

function ShowImage(img, pt, border) {
    if (img == null) return;

    var Forms = forms.System.Windows.Forms;
    if (border == null) border = 0;
    if (border != 0) { pt = new Point(pt.X - border, pt.Y - border); }

    var form = new Forms.Form;
    form.StartPosition = Forms.FormStartPosition.Manual;
    form.FormBorderStyle = (border != 0) ? //border != 0白框
        Forms.FormBorderStyle.None :
        Forms.FormBorderStyle.SizableToolWindow ;
    form.TopMost = true;
    form.ControlBox = false;
    form.ShowInTaskbar = false;
    form.Margin = new Forms.Padding(0);
    if (border != 0) { form.Padding = new Forms.Padding(border); }
    form.MinimumSize = new Size(10, 10);
    form.Size = new Size(10, 10);
    form.Location = pt;
    form.AutoSize = true;
    form.GetType().GetProperty("DoubleBuffered",
        host.flags(clr.System.Reflection.BindingFlags.NonPublic,
        clr.System.Reflection.BindingFlags.Instance))
        .SetValue(form, true);
    form.BackColor = drawing.System.Drawing.SystemColors.HotTrack;

    var pic = new Forms.PictureBox;
    pic.Name = 'pic';
    pic.SizeMode = Forms.PictureBoxSizeMode.Zoom;
    pic.Size = new Size(img.Width, img.Height);
    pic.BackColor = drawing.System.Drawing.SystemColors.Control;
    if (border != 0) { pic.Location = new Point(border, border); }
    pic.Image = img;

    form.Controls.Add(pic);
    var autoSize = form.Size;
    var t = (form.ClientSize.Width - pic.Width - form.Padding.Horizontal);
    autoSize.Width -= t;
    autoSize.Height -= t;
    form.AutoSize = false;
    form.Size = autoSize;
    pic.Dock = Forms.DockStyle.Fill;

    var form_shown = 
    form.Shown.connect(
    function (sender, args) {
        form.TopMost = true;
        form.Activate();
        if(sp.IsKeyToggled(vk.CAPITAL)){
            sp.SendVKey(vk.CAPITAL);
        }
    });

    var pic_doubleClick = 
    pic.DoubleClick.connect(
    function (sender, args) {
        var currentMouseLocation = sp.GetCurrentMousePoint();
        form.Close();
        FlushMemory();
    });

    menuBlind = ShowImageBindAllMenu(form, pic);
    dragMoveBlind = ShowImageBindDragMove(form, pic);
    wheelResizeBlind = ShowImageBindWheelResize(form, pic);
    


    Forms.Application.Run(form);
}

function ShowImageBindWheelResize(form, pic) {
    var form_mouseWheel = 
    form.MouseWheel.connect(
    function (sender, e) {
        var factor = e.Delta / 1000;
        var ampt = forms.System.Windows.Forms.Control.MousePosition;
        var rmpt = new Point();
        rmpt.X = ampt.X - form.Left;
        rmpt.Y = ampt.Y - form.Top;
        var intFunc = Math.floor;
        rmpt.X +=  intFunc(rmpt.X * factor);
        rmpt.Y +=  intFunc(rmpt.Y * factor);
        form.SetBounds(ampt.X - rmpt.X, ampt.Y - rmpt.Y, 
        form.Width + intFunc(form.Width *  factor), 
        form.Height + intFunc(form.Height *  factor));
    });
    return [form_mouseWheel];
}
function ShowImageBindAllMenu(form, pic) {
    var Forms = forms.System.Windows.Forms;

    var contextMenu1 = new Forms.ContextMenu();
    var menu1 = contextMenu1.MenuItems.Add("Save File");

    // item 1
    var saveFileDialog1  = new Forms.SaveFileDialog();
    saveFileDialog1.Filter = "png files (*.png)|*.png" ;
    saveFileDialog1.RestoreDirectory = true ;
    //saveFileDialog1.FileName = clr.System.DateTime.Now.ToString().replace(/[/\*?":<>| ]/g, '_');
    
    var d = new Date();
    saveFileDialog1.FileName = "StrokesPlus.net-"+d.getFullYear()
                     + "-"
                     + ("0" + (d.getMonth()+1)).slice(-2)
                     + "-"
                     + ("0" + d.getDate()).slice(-2)
                     + "-"
                     + ("0" + d.getHours()).slice(-2) 
                     +  "" 
                     + ("0" + d.getMinutes()).slice(-2)
                     +  "" 
                     + ("0" + d.getSeconds()).slice(-2);


    var menu1_click  = menu1.Click.connect(function (sender, e) {
        if (saveFileDialog1.ShowDialog() == Forms.DialogResult.OK) {
            pic.Image.Save(saveFileDialog1.FileName, drawing.System.Drawing.Imaging.ImageFormat.Png);
        }
    });

    pic.ContextMenu = contextMenu1;

    return [menu1_click];
}
function ShowImageBindDragMove(form, pic) {
    var Cursors = forms.System.Windows.Forms.Cursors;
    var ReleaseCapture = sp_config.GetType().Assembly.GetType("API").GetMethod("ReleaseCapture");

    var pic_mouseMove = 
    pic.MouseMove.connect(
    function (sender, e) {
        var hitResize = form.Height + form.Width - (e.X + e.Y) < 30;
        var cursor = hitResize ? Cursors.SizeNWSE : Cursors.Default;
        if (pic.Cursor != cursor) pic.Cursor = cursor;
        if (e.Button == MouseButtons.Left) {
            ReleaseCapture.Invoke(null, null);
            sp.WindowFromHandle(form.Handle).SendMessageObj(0x0112,
                hitResize ? 0xF008 : 0xF012, 0);
        }
    });

    return [pic_mouseMove];
}

        function FlushMemory()
        {
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
            if (System.Environment.OSVersion.Platform == System.PlatformID.Win32NT)
                NativeModules.Kernel32.SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
        } 
                

截图OCR(调用win10截图快捷键,百度OCR接口,结果保存至剪切板)

自选结果同时显示桌面左下角,2s自动关闭显示


var clientId = "1UVb6fiUzC1hyzwT2zvsOcwi";
var clientSecret = "de1XdmFwNKx32NWw3b4LHsPh0AvyyALT";

var startimage = clip.GetImage();

sp.SendModifiedVKeys([vk.LSHIFT,vk.LWIN], [vk.VK_S]);

//sp.Sleep(100);
for(i=0; i< 6000; i++) {
//ScreenClippingHost
    
    sp.Sleep(1000);
    var wnd = sp.WindowsFromTitlePartial("屏幕截图");
    var currimage = clip.GetImage();
    if(i > 0 && wnd.Count() === 0 && clip.ContainsImage()) {

            sp.Sleep(100); 

            var ms = new clr.System.IO.MemoryStream();
            currimage.Save(ms, drawing.System.Drawing.Imaging.ImageFormat.Png);
            ms.Position = 0;
            var base64Img = clr.System.Convert.ToBase64String(ms.GetBuffer());
            var imgHTML = "<img alt='Clipped Image' src='" + "data:image/png;base64," + base64Img + "' />";
            clip.SetText(imgHTML);
            ms.Close();

            var authHost = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + clientId + "&client_secret=" + clientSecret;
            var client = new http.System.Net.Http.HttpClient();
            var json = client.GetStringAsync(authHost);
            var obj = JSON.parse(json.Result);
            client.Dispose();

            if (obj.access_token) {
                var token = obj.access_token;
                var ocrHost = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=" + token;
                var request = clr.System.Net.WebRequest.Create(ocrHost);
                request.Method = "post";
                var encoding = clr.System.Text.Encoding.Default;
                var paraString = "image=" + clr.System.Net.WebUtility.UrlEncode(base64Img);
                var buffer =  encoding.GetBytes(paraString);
                request.ContentLength = buffer.Length;
                request.GetRequestStream().Write(buffer, 0, buffer.Length);

                var response = request.GetResponse();
                var reader = new clr.System.IO.StreamReader(response.GetResponseStream(), clr.System.Text.Encoding.UTF8);
                var result = reader.ReadToEnd();

                var json = JSON.parse(result);
                var jsonArray = json.words_result;
                if (jsonArray) {
                    var OCRText = "";
                    for(var i=0; i<jsonArray.length; i++) {
                        OCRText += jsonArray[i].words
                    }
                    if (OCRText.length) {
                        clip.SetText(OCRText);
                        //clr.System.Media.SystemSounds.Asterisk.Play();
                    }
                }
                else {
                    clip.SetText(result);
                }
                
                response.Dispose();
                reader.Dispose();
            }

        //以下break前的注释代码内容为屏幕左下角显示OCR结果,根据需要选用

        /*var info = new DisplayTextInfo();
        //info.Title = 'Test';
        info.TitleAlignment = 'Center';
        info.Message = clip.GetText();
        info.MessageAlignment = 'Left';
        info.Duration = 2000;
        //弹出窗口的透明度,有效范围:0.05  -  1.0(1.0不透明)
        info.Opacity = 0.5;
        //位置也支持位置,使用此格式指定类型:'100,200'
        //类型:topleft,top,topright,right,bottomright,bottom,bottomleft,left
        info.Location = 'bottom'; 
        info.TitleFont = new Font('Segoe UI', 12, host.flags(FontStyle.Bold));
        info.MessageFont = new Font('Segoe UI Semibold', 12);
        //info.BackColor = '56,169,255';//'56,169,255'; //也支持 RGBinfo.ForeColor = 'white';
        info.BackColor = "105,105,105";             
        info.Padding = 10;//大小
        //如果为true,则始终显示在主屏幕上(除非Location是点类型),
        //否则会在手势开始的屏幕上显示
        info.UsePrimaryScreen = true; 
        sp.DisplayText(info);
        //sp.DisplayTextUpdate(info);
        */

        break;
    }
}

截图保存桌面(调用win10截图快捷键)


var startimage = clip.GetImage();

sp.SendModifiedVKeys([vk.LSHIFT,vk.LWIN], [vk.VK_S]);

sp.Sleep(10);//延时进入截图界面时间
for(i=0; i< 6000; i++) {
//ScreenClippingHost

    sp.Sleep(1000);
    var wnd = sp.WindowsFromTitlePartial("屏幕截图");
    sp.Sleep(200);
    var currimage = clip.GetImage();

    if(i > 0 && wnd.Count() === 0 && clip.ContainsImage()) {

                var env = clr.System.Environment;
                var desktop = env.GetFolderPath(env.SpecialFolder.DesktopDirectory);
                var d = new Date();
                var dateString = "image-"+d.getFullYear()
                                 + "-"
                                 + ("0" + (d.getMonth()+1)).slice(-2)
                                 + "-"
                                 + ("0" + d.getDate()).slice(-2)
                                 + " "
                                 + ("0" + d.getHours()).slice(-2) 
                                 +  "" 
                                 + ("0" + d.getMinutes()).slice(-2)
                                 +  "" 
                                 + ("0" + d.getSeconds()).slice(-2);

                sp.Sleep(100);
                currimage.Save(
                    `${desktop}\\${dateString}.png`, 
                    drawing.System.Drawing.Imaging.ImageFormat.Png)
                sp.Sleep(100);
                sp.StoreBool("store", true);
                sp.CreateTimer('store', 700, -1, String.raw`sp.StoreBool("store", false);sp.DeleteTimer('store');`);
            break;


    }
}

输入法英文状态的时候桌面下方提示,Shift切换后关闭

代码由作者发布S+net官方论坛,依据AHK输入法状态查询

如果不需要提示输入法状态,只需要大写键按下提示,弹起提示关闭,添加第二部分代码,并且注释开始结束之间的代码

添加到全局动作-启动/退出-启动(开启)

第一部分

//Define IME constants
const WM_IME_CONTROL = 0x283;
const IMC_GETOPENSTATUS = 0x005;

//If the Imm32 module has not already been defined
if(!NativeModules.Imm32)
{
    var IntPtrT = host.typeOf(System.IntPtr);

    //Define imm32 type
    var imm32TB = sp.NativeModule().DefineType("Imm32", "Class,Public,SequentialLayout,Serializable");
         
        //Define the platform invoke call
        //From: https://docs.microsoft.com/en-us/windows/win32/api/imm/nf-imm-immgetdefaultimewnd
        imm32TB.DefinePInvokeMethod("ImmGetDefaultIMEWnd",
                                                                 "imm32.dll",
                                                                 [IntPtrT],
                                                                 IntPtrT,
                                                                 "PreserveSig");        

        //Create the type (finalize, now made an official C# class)                                         
    imm32TB.Create();                                                                 

    //Note: Changes cannot be made to a class once created. If you need to change or add
    //      anything, you must restart S+ to update the class.
}

第二部分

sp.CreateTimer("LangWatch",
               250,
               250,
               `var info = new DisplayTextInfo();
                 
               info.TitleFont = new Font('Segoe UI', 12, host.flags(FontStyle.Bold));
               info.MessageFont = new Font("Segoe UI Semibold", 12);
               info.BackColor = "15,179,98";  //绿
               info.ForeColor = "255,255,255";
               info.Duration = 1000;
               info.Opacity = 0.5;
               //info.Location = "679,765";
               info.Location = "190,809";
               //info.Location = "0,0";
               //info.Location = "bottom";
               //info.FadeSteps = 10;
               info.Padding = 10;
               info.Message = "";

                if(sp.IsKeyToggled(vk.CAPITAL)) {//大写键监控
                    info.Message = "CAPS Lock is ON";

                }

                //开始
                var imeWnd = NativeModules.Imm32.ImmGetDefaultIMEWnd(sp.ForegroundWindow().HWnd);

                //Send the message and store return value
                var ret = sp.WindowFromHandle(imeWnd).SendMessageObj(WM_IME_CONTROL, IMC_GETOPENSTATUS, 0x0);


                if(ret.ToInt32() === 0) {
                    if(info.Message.length > 0) {
                        info.Message += " - ";
                        info.BackColor = "255,105,180";//粉
                        info.Location = "190,809";
                    } else {
                        info.BackColor = "56,142,142";//墨绿
                        info.Location = "325,809";
                    }
                    info.Message += "En Keyboard ACTIVE";  
                }
                //结束

                if(info.Message.length > 0) {
                    if(sp.GetStoredBool("LangShown")) {
                        sp.DisplayTextUpdate(info);
                    } else {
                        sp.DisplayText(info);
                        sp.StoreBool("LangShown", true);
                    }
                } else {
                    //sp.DisplayTextClose();
                    sp.StoreBool("LangShown", false);
                }
               `
);

设置当前输入法为中文或者英文,不管当前输入法任何状态

重要:需要在启动/退出-启动(开启) 中添加 7# 第一部分代码

设置中文输入法

const WM_IME_CONTROL_a = 0x283;
const IMC_GETOPENSTATUS_a = 0x006;
sp.WindowFromHandle(imeWnd).SendMessageObj(WM_IME_CONTROL_a, IMC_GETOPENSTATUS_a, 0x1);

设置英文输入法

const WM_IME_CONTROL_b = 0x283;
const IMC_GETOPENSTATUS_b = 0x006;
sp.WindowFromHandle(imeWnd).SendMessageObj(WM_IME_CONTROL_b, IMC_GETOPENSTATUS_b, 0x0);

压缩选中文件、文件夹

使用7z命令行实现:

a 选中1个文件、文件夹,直接压缩
b 选中多个文件,或者文件夹,压缩时新建一个子文件夹

如果压缩文件名已存在,新建压缩文件名字自动加1
暂时不支持压缩时指定压缩路径暂未考虑压缩时加密的情况
提示:由于7z命令行限制,新建的子文件夹不是真实文件夹,手动解压时正常,文件数量较大时会卡顿

 压缩选中文件、文件夹.zip - 蓝奏云

var result;
var selectedFiles;
var fullPath = ""; 
var isDesktop = false;
var success = false;
var path = "";
var fileNameNoExt;
var allFile = "";
var filepath = "";
var filespath = "";
var archivename;
var onlyNames = true; //Only include the name, not the full path and name
var includeFolders = true; //Include folders as well as files
var includeLinks = true; //Include links (shortcuts)
var n = 0;
var m = "";
var str = "C:\\Users\\Administrator\\Desktop";
var foldinfo = new System.IO.DirectoryInfo(str);
var desktopfilescount = foldinfo.EnumerateFileSystemInfos().Count();

if(action.Control.HWnd.ToInt32() == sp.DesktopWindowListView().HWnd.ToInt32()) {
    //Desktop
    selectedFiles = sp.GetSelectedFilesOnDesktop();
    isDesktop = true;
} else {
    //Not Desktop
    selectedFiles = sp.GetSelectedFilesInExplorer(action.Window.HWnd);
}

fullPath = selectedFiles[0]; //选中文件路径
path = sp.GetActiveExplorerPath(action.Window.HWnd); //窗口路径
fileNameNoExt = System.IO.Path.GetFileNameWithoutExtension(fullPath);
allFile = sp.GetItemsInExplorer(action.Window.HWnd, onlyNames, includeFolders, includeLinks); //资源管理器文件名

if(isDesktop) {
    fullPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + "\\" + fullPath;
    path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);
    fileNameNoExt = System.IO.Path.GetFileNameWithoutExtension(fullPath);

    for(i = 0; i < desktopfilescount; i++) 
    {
        if(System.IO.File.Exists(path + "\\新建压缩文件" + m + ".zip") || 
            System.IO.File.Exists(path + "\\" + fileNameNoExt + m + ".zip")) {
            n = n + 1;
            m = " (" + n + ")";
            //m = "_" + n;
        }
    }
} else {
    for(i = 0; i < allFile.Length; i++)
    {
        if(("新建压缩文件" + m + ".zip") == allFile[i] || 
            (fileNameNoExt + m + ".zip") == allFile[i]) {
            n = n + 1;
            m = " (" + n + ")";
            //m = "_" + n;
        }
    }
}

if(selectedFiles.Length == 1) {
    filepath = fullPath;
    archivename = path + "\\" + fileNameNoExt + m + ".zip";
    result = sp.RunProgram('C:\\Program Files\\7-Zip\\7z.exe', 
                                       `a "${archivename}" "${filepath}"`,
                                       'open', 'hidden', false, true, true);
} else if(selectedFiles.Length > 1) {
    for(i = 0; i < selectedFiles.Length; i++)
    {
        fullPath = selectedFiles[i];

        if(isDesktop) {
            fullPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + "\\" + fullPath;
        }
        filespath = filespath + " " + "\"" + fullPath + "\"";
    }
    archivename = path + "\\新建压缩文件" + m + ".zip";
    StrokesPlus.Console.Log(filespath);
    sp.RunProgram('C:\\Program Files\\7-Zip\\7z.exe', 
                                       `a "${archivename}" ${filespath}`,
                                       'open', 'hidden', false, true, true);

    var p = new System.Diagnostics.Process();
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.FileName = "C:\\Program Files\\7-Zip\\7z.exe";
    p.StartInfo.CreateNoWindow = true;
    p.StartInfo.Arguments = "l \"" + archivename + "\""
    p.Start();
    var output = p.StandardOutput.ReadToEnd();
    p.WaitForExit();

    var lines = output.split(/\r\n|\n\r|\n|\r/);

    // skipping last line to ignore the summary line
    // but yeah,  tweak as needed
    for(var i = 0; i < lines.length - 2; i++) {
        if(/^[0-9]{4}-/.test(lines[i])) {
            var zipfilepath = lines[i].slice(53);
            var temzipfilepath = "新建文件夹\\" + zipfilepath;
            result = sp.RunProgram('C:\\Program Files\\7-Zip\\7z.exe', 
                                       `rn ${archivename} "${zipfilepath}" "${temzipfilepath}"`,
                                       'open', 'hidden', false, true, true); 

        }
    }
}


if(result == 0) { 
    success = true;
    sp.ShowBalloonTip("ZIP Extract", "Success", "info", 1000);
} 
if(!success) {
    sp.ShowBalloonTip("ZIP", "Failed", "error", 1000);
}

解压缩到当前文件夹(7Zip)
1 选中1个zip、rar文件,包含:
a 1个文件或者1个文件夹
直接解压到当前路径
b 多个文件、文件夹
解压到当前新建同名文件夹

2 多个压缩文件,
直接分别解压到当前路径

如果压缩包内文件名当前路径已存在,解压后文件名字自动加1
暂时不支持解压时指定解压路径
暂时还未测试解压分卷文件情况
如需解压加密压缩包留言
如果有需要快捷键,修改下设置到Hotkey

更新:
20220305 修复压缩包内有文件夹,命令行显示没有文件夹不能解压的问题

var result;
var fullPath = "";
var outdir = "";
var selectedFiles;
var isDesktop = false;
var success = false;

if(action.Control.HWnd.ToInt32() == sp.DesktopWindowListView().HWnd.ToInt32()) {
    //Desktop
    selectedFiles = sp.GetSelectedFilesOnDesktop();
    isDesktop = true;
} else {
    //Not Desktop
    selectedFiles = sp.GetSelectedFilesInExplorer(action.Window.HWnd);
}

fullPath = selectedFiles[0];

if(isDesktop) {
    fullPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + "\\" + fullPath;
}

var fileNameNoExt = System.IO.Path.GetFileNameWithoutExtension(fullPath);
var folderName = System.IO.Path.GetDirectoryName(fullPath);

outdir = folderName + "\\" + fileNameNoExt;

//用于l 路径
var path = fullPath.replaceAll("\\","\\\\")
var p = new System.Diagnostics.Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "C:\\Program Files\\7-Zip\\7z.exe";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.Arguments = "l \"" + path + "\" -x!*\\?*";
p.Start();
var output = p.StandardOutput.ReadToEnd();
p.WaitForExit();

var lines = output.split(/\r\n|\n\r|\n|\r/);
var filenum = 0;
var foldnum = 0;
var filepath = "";
var str = "";


// skipping last line to ignore the summary line
// but yeah,  tweak as needed
//第一层文件 文件夹数量
for(var i = 0; i < lines.length - 1; i++) {
    if(/^[0-9]{4}-/.test(lines[i])) {
        if(i = lines.length - 2) {
            if(lines[lines.length - 2].indexOf("folders") > -1) {
                foldnum = lines[lines.length - 2].split(', ')[1].split(' folders')[0];
            }
            if(lines[lines.length - 2].indexOf("files") > -1) {
                filenum = lines[lines.length - 2].slice(53).split(' files')[0];
            }
        } 

    }
}


if(selectedFiles.Length == 1) {
    if((filenum == 1 && foldnum == 0) || (filenum == 0 && foldnum == 1) || (filenum == 0 && foldnum == 0)) { //当前文件夹 文件数1 文件夹0 或 文件数0 文件夹1
        result = sp.RunProgram('C:\\Program Files\\7-Zip\\7z.exe', 
                                           `x "${fullPath}" -o"${folderName}" -aou`, 
                                           'open', 'hidden', false, true, true); 
    } else if((filenum > 1 && foldnum == 0) || (filenum == 0 && foldnum > 1) || (filenum > 0 && foldnum > 0)) { //同名文件夹 文件数>1 文件夹0 或 文件数0 文件夹>1 或 文件数>0 文件夹>0
        result = sp.RunProgram('C:\\Program Files\\7-Zip\\7z.exe', 
                                   `x "${fullPath}" -o"${outdir}" -aou`, 
                                   'open', 'hidden', false, true, true);
    }
} else if(selectedFiles.Length > 1) { //批量解压缩
    for(i = 0; i < selectedFiles.Length; i++)
    {
        tempfullPath = selectedFiles[i];

        if(isDesktop) {
            tempfullPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + "\\" + tempfullPath;
        }
        var tempfolderName = System.IO.Path.GetDirectoryName(tempfullPath);
        //直接解压到当前路径
        result = sp.RunProgram('C:\\Program Files\\7-Zip\\7z.exe', 
                                           `x "${tempfullPath}" -o"${tempfolderName}" -aou`, 
                                           'open', 'hidden', false, true, true); 
    }
} else {

}

if(result == 0) { 
    success = true;
    sp.ShowBalloonTip("ZIP Extract", "Success", "info", 1000);
    
} 
if(!success) {
    sp.ShowBalloonTip("ZIP Extract", "Failed", "error", 1000);
}

鼠标穿屏

鼠标在屏幕上下左右边界穿过到另一侧,如果使用多个屏幕需要调整下代码

可以添加到 光标移动到屏幕角落执行任务 13# 计时器中

添加到全局动作-启动/退出-启动(开启)

sp.CreateTimer("CornerCheck",
                         0,
                         200,
                         `var mousePos = sp.GetCurrentMousePoint();
                        var mouseScreen = Screen.FromPoint(mousePos);
                        if(mousePos.X == mouseScreen.Bounds.Right - 1 && mousePos.Y > mouseScreen.Bounds.Top + 10 && mousePos.Y < mouseScreen.Bounds.Bottom - 10) {
                            //Right
                            sp.MouseMove(new Point(1, mousePos.Y));
                        } else if(mousePos.X == mouseScreen.Bounds.Left && mousePos.Y > mouseScreen.Bounds.Top + 10 && mousePos.Y < mouseScreen.Bounds.Bottom - 10) {
                            //Left
                            sp.MouseMove(new Point(mouseScreen.Bounds.Right  - 14, mousePos.Y));
                        } else if(mousePos.Y == mouseScreen.Bounds.Top && mousePos.X > mouseScreen.Bounds.Left + 10 && mousePos.X < mouseScreen.Bounds.Right - 10) {
                            //Top
                            sp.MouseMove(new Point(mousePos.X, mouseScreen.Bounds.Bottom  - 18));
                        } else if(mousePos.Y == mouseScreen.Bounds.Bottom - 1 && mousePos.X > mouseScreen.Bounds.Left + 10 && mousePos.X <  mouseScreen.Bounds.Right - 10) {
                            //Bottom
                            sp.MouseMove(new Point(mousePos.X, 1));
                        }`
);

任意窗口搜索输入内容

类似于 Power Toys 或者 Listary.

输入框默认显示屏幕正中间,输入的时候需要一个识别字母 空格 加内容:g 内容

几个搜索引擎,通过识别字母选择:
b Baidu
bi Bing
d Duckduckgo
g Google
w Wikipedia
y Youtube

快捷键 Ctrl+Shift+J 激活输入框,或者再次按后关闭输入框,按下回车进行搜索,ESC同样关闭输入框
双击输入框,任意拖动

var ht = sp.ForegroundWindow().Screen.Bounds.Height;
var wd = sp.ForegroundWindow().Screen.Bounds.Width;

var input = "";

var Forms = forms.System.Windows.Forms;
var form = new Forms.Form;

form.StartPosition = Forms.FormStartPosition.Manual;
form.FormBorderStyle = Forms.FormBorderStyle.FixedToolWindow;
form.TopMost = true;
form.ControlBox = false;
form.ShowInTaskbar = false;
form.Margin = new Forms.Padding(0);
form.Padding = new Forms.Padding(1); 
form.MinimumSize = new Size(100, 10);
//form.Size = new Size(300, 26);
form.Size = new Size(300, 34);
//form.Location = currentMouseLocation;
form.Location = new Point(wd/2 - 150, ht/2 - 60);
form.AutoSize = true;
form.GetType().GetProperty("DoubleBuffered",
        host.flags(clr.System.Reflection.BindingFlags.NonPublic,
        clr.System.Reflection.BindingFlags.Instance))
        .SetValue(form, true);
form.BackColor = Color.WhiteSmoke;

var textBox = new Forms.TextBox;
textBox.Size = new Size(150, 20);
textBox.Location = new Point(50, 5);
//textBox.Font = new System.Drawing.Font("Microsoft YaHei", 8, FontStyle.Regular);
textBox.Font = new System.Drawing.Font("Microsoft YaHei", 13, FontStyle.Regular);
textBox.Text = "";
textBox.Dock = System.Windows.Forms.DockStyle.Fill;
form.Controls.Add(textBox);

dragMoveBlind = ShowImageBindDragMove(form, form);
dragMoveBlind = ShowImageBindDragMove(form, textBox);

var form_shown = 
form.Shown.connect(
function (sender, args) {
    form.TopMost = true;
    form.Activate();
});

var textBox_KeyPress = 
textBox.KeyPress.connect(
function (sender, e) {
    // The keypressed method uses the KeyChar property to check 
    // whether the ENTER key is pressed. 
    // then, do action and close the Form
    if (e.KeyChar == 13)
    {
        input = textBox.Text;
        form.Close();
    // The keypressed method uses the KeyChar property to check 
    // whether the ESCAPE key is pressed. 
    // then close the Form
    } else if(e.KeyChar == 27) {
        form.Close();
    }
});

var textBox_KeyDown = 
textBox.KeyDown.connect(
function (sender, e) {
    // The keydown method uses the KeyChar property to check 
    // whether the Ctrl+SHIFT+J key is pressed. 
    // then, close the Form
    var hk = e.KeyCode
    if((e.Control) && (e.KeyCode==System.Windows.Forms.Keys.J) && (e.Shift)) {
        form.Close();
        StrokesPlus.Console.Log('OK');
    }
});

// Enable to double click the mouse right button to 
// drag the From
var textBox_doubleClick = 
textBox.DoubleClick.connect(
function (sender, args) {
  dragMoveBlind = ShowImageBindDragMove(form, textBox);
});

var form_doubleClick = 
form.DoubleClick.connect(
function (sender, args) {
  dragMoveBlind = ShowImageBindDragMove(form, form);
});

Forms.Application.Run(form);

function ShowImageBindDragMove(form, item) {
    var Cursors = forms.System.Windows.Forms.Cursors;
    var ReleaseCapture = sp_config.GetType().Assembly.GetType("API").GetMethod("ReleaseCapture");

    var item_mouseMove = 
    item.MouseMove.connect(
    function (sender, e) {
        var hitResize = form.Height + form.Width - (e.X + e.Y) < 30;
        var cursor = hitResize ? Cursors.SizeNWSE : Cursors.IBeam;
        if (item.Cursor != cursor) item.Cursor = cursor;
        if (e.Button == MouseButtons.Left) {
            ReleaseCapture.Invoke(null, null);
            sp.WindowFromHandle(form.Handle).SendMessageObj(0x0112,
                hitResize ? 0xF008 : 0xF012, 0);
        }
    });

    return [item_mouseMove];
}


if((input !== '')) {
    var kwd = '';
    var str = '';

    if(input.slice(0, 2) == 'b ') {
        str = 'https://www.baidu.com/s?wd=';
        kwd = input.slice(2);
    } else if(input.slice(0, 3) == 'bi ') {
        str = 'https://cn.bing.com/search?q=';
        kwd = input.slice(3);
    } else if(input.slice(0, 2) == 'd ') {
        str = 'https://duckduckgo.com/?q=';
        kwd = input.slice(2);
    } else if(input.slice(0, 2) == 'g ') {
        str = 'https://www.google.com/search?q=';
        kwd = input.slice(2);
    } else if(input.slice(0, 2) == 'w ') {
        str = 'https://zh.wikipedia.org/w/index.php?search=';
        kwd = input.slice(2);
    } else if(input.slice(0, 2) == 'y ') {
        str = 'https://www.youtube.com/results?search_query=';
        kwd = input.slice(2);
    }
    if(str !== '') {
        sp.RunProgram(str + kwd, '', 'open', 'normal', true, false, false);
    }
}

光标移动到屏幕角落执行任务

添加到全局动作-启动/退出-启动(开启)

sp.CreateTimer("CornerCheck", 0, 200, `
                               var mousePos = sp.GetCurrentMousePoint();
                               var mouseScreen = Screen.FromPoint(mousePos);
                               if(mousePos.X == mouseScreen.Bounds.Right - 1 && mousePos.Y == mouseScreen.Bounds.Top) {
                                    //右上角动作
                                    //sp.MessageBox("In upper right corner!", "Hi");
                                    if(!sp.GetStoredBool("CornerCheckActive")) {
                                        sp.SendModifiedVKeys([vk.LMENU], [vk.F4]);//关闭窗口
                                        sp.StoreBool("CornerCheckActive", true);
                                    } 
                               } else if(mousePos.X == mouseScreen.Bounds.Right - 1 && mousePos.Y == mouseScreen.Bounds.Bottom - 1) {
                                    //右下角动作
                                    //sp.MessageBox("In lower right corner!", "Hi");
                                    if(!sp.GetStoredBool("CornerCheckActive")) {
                                        sp.SendModifiedVKeys([vk.LWIN], [vk.VK_D]);//显示桌面
                                        sp.StoreBool("CornerCheckActive", true);
                                    } 
                               } else if(mousePos.X == mouseScreen.Bounds.Left && mousePos.Y == mouseScreen.Bounds.Top) {
                                    //左上角动作
                                    //sp.MessageBox("In upper left corner!", "Hi");
                                    if(!sp.GetStoredBool("CornerCheckActive")) {
                                        //添加代码到此处,然后注释或删除下方的sp.MessageBox
                                        sp.StoreBool("CornerCheckActive", true);
                                        sp.MessageBox("In upper left corner!", "Hi");
                                    } 
                               } else if(mousePos.X == mouseScreen.Bounds.Left && mousePos.Y == mouseScreen.Bounds.Bottom - 1) {
                                    //左下角动作
                                    //sp.MessageBox("In lower left corner!", "Hi");
                                    if(!sp.GetStoredBool("CornerCheckActive")) {
                                        sp.SendVKey(vk.LWIN);
                                        sp.StoreBool("CornerCheckActive", true);
                                    } 
                               }  else {
                                    sp.StoreBool("CornerCheckActive", false);
                               }`
);

关显示屏
sp.WindowFromHandle(new IntPtr(0xffff)).PostMessageObj(0x112, 0xf170, 2);

任务窗口
sp.SendModifiedVKeys([vk.LWIN], [vk.TAB]);

隐藏其他窗口
sp.SendModifiedVKeys([vk.LWIN], [vk.HOME]);

选中图片预览 v1.2

    更新:

  • 20220211 v0.2
     1. 图片宽度大于450,显示图片宽度为450,图片宽度小于450,显示原尺寸,高度不限制
     2. 显示图片位置在屏幕内

  • 20220217 v1.0
     3. 解决预览显示后,资源管理器失焦的问题
     4. 解决文件夹点空白处不显示一次最后选中的图片问题
     5. 解决无法重命名(F2)、复制、剪切的问题

  • 20220219 v1.1
     6. 修复桌面显示图片预览后,只能双击预览关闭

  • 20220322 v1.2
     7. 更新双击关闭/预览关闭后,清除S+内存(见下方加粗提示)

资源管理器、桌面选中图片后,直接在鼠标处显示预览,点击空白处关闭预览,和双击左键关闭(用于切换其他窗口,预览未关闭情况),鼠标拖动,滚动放大缩小,选中下一张图片继续预览

Macbook Air测试,每800毫秒执行一次,如打开预览卡顿,可以设置高

存在小问题:
     1. 直接双击预览关闭,会再次显示
     2. 图片宽度过大(比如大于5000),预览关闭和选中下一张图片会卡,尝试从缓存中获取图片重绘设置大小,效果不明显

补充添加38# 代码到全局动作-启动/退出-启动

添加到全局动作-启动/退出-启动(开启)

if(!NativeModules.User32)
{
    var IntPtrT = host.typeOf(clr.System.IntPtr);
    var Int32T = host.typeOf(clr.System.Int32);
    var BooleanT = host.typeOf(clr.System.Boolean);
	
    var user32TB = sp.NativeModule().DefineType("User32", "Class,Public,SequentialLayout,Serializable");
	
	user32TB.DefinePInvokeMethod("ShowWindow",
								 "user32.dll",
								 [IntPtrT,Int32T], 
								 BooleanT, 
								 "PreserveSig");	

    user32TB.DefinePInvokeMethod("SetWindowPos",
								 "user32.dll",
								 [IntPtrT,Int32T,Int32T,Int32T,Int32T,Int32T,Int32T], 
								 BooleanT, 
								 "PreserveSig");

	user32TB.Create();
}

sp.CreateTimer("imagepreview", 
               0, 
               800, 
                `var currentMouseLocation = sp.GetCurrentMousePoint();
                var wndHandle = sp.ForegroundWindow().HWnd;
                var desktopHandle = sp.DesktopWindowListView().HWnd;

                var fullPath = "";
                var files;
                var isDesktop = false;
                var mouseScreen = Screen.FromPoint(currentMouseLocation);

                var oldFormHWD = sp.GetStoredHandle('formHWD');
                var oldSelFileName = sp.GetStoredString('selFileName');

                if(wndHandle.ToInt32() == desktopHandle.ToInt32() || sp.LastFocusControl().HWnd.ToInt32() == desktopHandle.ToInt32() ||
                                    sp.ForegroundWindow().ClassName == 'WorkerW' || sp.ForegroundWindow().ClassName == 'Progman') {
                    //Desktop
                    files = sp.GetSelectedFilesOnDesktop();
                    isDesktop = true;
                } else {
                    //Not Desktop
                        files = sp.GetSelectedFilesInExplorer(wndHandle);
                }
                    
                if(files.Length == 1 && (files[0].endsWith("png") || files[0].endsWith("PNG") ||
                        files[0].endsWith("jpg") || files[0].endsWith("JPG") || 
                        files[0].endsWith("jpeg") || files[0].endsWith("JPEG") || 
                        files[0].endsWith("bmp") || files[0].endsWith("BMP") ||  
                        files[0].endsWith("ico") || files[0].endsWith("ICO") ||
                        files[0].endsWith("gif") || files[0].endsWith("GIF"))) {
                    
                    fullPath = files[0];
                    
                    if(isDesktop) {
                        fullPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + "\\\\" + fullPath;
                    }

                    var fileNameNoExt = System.IO.Path.GetFileNameWithoutExtension(fullPath);
                    sp.StoreString('selFileName', fileNameNoExt);

                    if(sp.GetStoredString('selFileName') != oldSelFileName) {
                        sp.StoreBool('shown', false);
                    }

                    if(!sp.GetStoredBool('shown')) {
                        //ShowImage(fullPath, currentMouseLocation, 1);

                        var fs = new clr.System.IO.FileStream(fullPath, clr.System.IO.FileMode.Open, clr.System.IO.FileAccess.Read, clr.System.IO.FileShare.ReadWrite);
                        var fileBytes = host.newArr(System.Byte, fs.Length); 
                        fs.Read(fileBytes, 0, fs.Length);

                        fs.Close();
                        ShowImage(System.Drawing.Image.FromStream(new clr.System.IO.MemoryStream(fileBytes)), currentMouseLocation, 1);
                        //sp.DisplayImage(System.Drawing.Image.FromStream(new clr.System.IO.MemoryStream(fileBytes)), true);
                    }
                } else if((files.Length == 0 || files.Length > 1) && sp.ForegroundWindow().ClassName != 'WindowsForms10.Window.8.app.0.13965fa_r6_ad1') {
                    sp.WindowFromHandle(sp.GetStoredHandle('formHWD')).SendClose();
                    FlushMemory();
                    sp.StoreBool('shown', false);
                    sp.DeleteStoredHandle('formHWD');
                }

                function ShowImage(img, pt, border) {

                    if (img == null) return;

                    sp.WindowFromHandle(oldFormHWD).SendClose();
                    
                    var Forms = forms.System.Windows.Forms;
                    if (border == null) border = 0;
                    if (border != 0) { pt = new Point(pt.X - border, pt.Y - border); }

                    var foreWidth = System.Drawing.Image.FromStream(new clr.System.IO.MemoryStream(fileBytes)).Width;
                    var foreHeight = System.Drawing.Image.FromStream(new clr.System.IO.MemoryStream(fileBytes)).Height;
                    var afterHeight = parseInt(System.Drawing.Image.FromStream(new clr.System.IO.MemoryStream(fileBytes)).Height*420/System.Drawing.Image.FromStream(new clr.System.IO.MemoryStream(fileBytes)).Width);

                    var form = new Forms.Form;
                    form.StartPosition = Forms.FormStartPosition.Manual;
                    form.FormBorderStyle = (border != 0) ? //border != 0顶部白框
                        Forms.FormBorderStyle.None :
                        Forms.FormBorderStyle.SizableToolWindow ;
                    form.TopMost = true;
                    form.ControlBox = false;
                    form.ShowInTaskbar = false;
                    form.Margin = new Forms.Padding(0);
                    if (border != 0) { form.Padding = new Forms.Padding(border); }
                    form.MinimumSize = new Size(10, 10);
                    form.Size = new Size(10, 10);
                    if(foreWidth > 450) {
                        if(currentMouseLocation.X < mouseScreen.Bounds.Right - 1 - 450 && currentMouseLocation.Y > mouseScreen.Bounds.Bottom - 1 - afterHeight) {
                            form.Location = new Point(currentMouseLocation.X, mouseScreen.Bounds.Bottom - 41 - afterHeight);
                        } else if(currentMouseLocation.X > mouseScreen.Bounds.Right - 1 - 450 && currentMouseLocation.Y < mouseScreen.Bounds.Bottom - 1 - afterHeight){
                            form.Location = new Point(mouseScreen.Bounds.Right - 1 - 450, currentMouseLocation.Y);
                        } else if(currentMouseLocation.X > mouseScreen.Bounds.Right - 1 - 450 && currentMouseLocation.Y > mouseScreen.Bounds.Bottom - 1 - afterHeight){
                            form.Location = new Point(mouseScreen.Bounds.Right - 1 - 450, mouseScreen.Bounds.Bottom - 41 - afterHeight);
                        } else {               
                            form.Location = pt;
                        }
                    } else {
                        if(currentMouseLocation.X < mouseScreen.Bounds.Right - 1 - foreWidth && currentMouseLocation.Y > mouseScreen.Bounds.Bottom - 1 - foreHeight) {
                            form.Location = new Point(currentMouseLocation.X, mouseScreen.Bounds.Bottom - 41 - foreHeight);
                        } else if(currentMouseLocation.X > mouseScreen.Bounds.Right - 1 - foreWidth && currentMouseLocation.Y < mouseScreen.Bounds.Bottom - 1 - foreHeight) {
                            form.Location = new Point(mouseScreen.Bounds.Right - 1 - foreWidth, currentMouseLocation.Y);
                        } else if(currentMouseLocation.X > mouseScreen.Bounds.Right - 1 - foreWidth && currentMouseLocation.Y > mouseScreen.Bounds.Bottom - 1 - foreHeight) {
                            form.Location = new Point(mouseScreen.Bounds.Right - 1 - foreWidth, mouseScreen.Bounds.Bottom - 41 - foreHeight);
                        } else {               
                            form.Location = pt;
                        }
                    }
                    form.AutoSize = true;
                    form.GetType().GetProperty("DoubleBuffered",
                        host.flags(clr.System.Reflection.BindingFlags.NonPublic,
                        clr.System.Reflection.BindingFlags.Instance))
                        .SetValue(form, true);

                    //透明边框
                    form.BackColor = Color.LimeGreen;
                    form.TransparencyKey = Color.LimeGreen;

                    var pic = new Forms.PictureBox;
                    pic.Name = 'pic';
                    pic.SizeMode = Forms.PictureBoxSizeMode.Zoom;
                    if(System.Drawing.Image.FromStream(new clr.System.IO.MemoryStream(fileBytes)).Width > 450) {
                        pic.Size = new Size(450, parseInt(System.Drawing.Image.FromStream(new clr.System.IO.MemoryStream(fileBytes)).Height*420/System.Drawing.Image.FromStream(new clr.System.IO.MemoryStream(fileBytes)).Width));
                    } else {
                        pic.Size = new Size(System.Drawing.Image.FromStream(new clr.System.IO.MemoryStream(fileBytes)).Width, System.Drawing.Image.FromStream(new clr.System.IO.MemoryStream(fileBytes)).Height);
                    }
                    pic.BackColor = Color.Transparent;//背景透明
                    if (border != 0) { pic.Location = new Point(border, border); }
                    pic.Image = img;
                    
                    //pic.Image = System.Drawing.Image.FromStream(new clr.System.IO.MemoryStream(fileBytes));

                    form.Controls.Add(pic);
                    var autoSize = form.Size;
                    var t = (form.ClientSize.Width - pic.Width - form.Padding.Horizontal);
                    autoSize.Width -= t;
                    autoSize.Height -= t;
                    form.AutoSize = false;
                    form.Size = autoSize;
                    pic.Dock = Forms.DockStyle.Fill;

                    var form_shown = 
                    form.Shown.connect(
                    function (sender, args) {
                        //form.TopMost = true;

                        var HWND_TOPMOST = -1;
                        var SWP_NOACTIVATE = 0x0010;
                        var SW_SHOWNOACTIVATE = 4;

                        NativeModules.User32.ShowWindow(form.Handle, SW_SHOWNOACTIVATE);
                        NativeModules.User32.SetWindowPos(form.Handle, HWND_TOPMOST,form.Left, form.Top, form.Width, form.Height,SWP_NOACTIVATE);
                        form.TopMost = false;
                        //form.Activate();
                        sp.StoreBool('shown', true);
                        sp.StoreHandle('formHWD', form.Handle);

                    });


                    var pic_doubleClick = 
                    pic.DoubleClick.connect(
                    function (sender, args) {
                        sp.StoreBool('shown', false);
                        sp.DeleteStoredHandle('formHWD');
                        form.Close();
                        FlushMemory();
                    });

                    var form_doubleClick = 
                    form.DoubleClick.connect(
                    function (sender, args) {
                        sp.StoreBool('shown', false);
                        sp.DeleteStoredHandle('formHWD');
                        form.Close();
                        FlushMemory();
                    });

                    dragMoveBlind = ShowImageBindDragMove(form, pic);
                    wheelResizeBlind = ShowImageBindWheelResize(form, pic);

                    Forms.Application.Run(form);

                }

                function ShowImageBindWheelResize(form, pic) {
                    var form_mouseWheel = 
                    form.MouseWheel.connect(
                    function (sender, e) {
                        var factor = e.Delta / 1000;
                        var ampt = forms.System.Windows.Forms.Control.MousePosition;
                        var rmpt = new Point();
                        rmpt.X = ampt.X - form.Left;
                        rmpt.Y = ampt.Y - form.Top;
                        var intFunc = Math.floor;
                        rmpt.X +=  intFunc(rmpt.X * factor);
                        rmpt.Y +=  intFunc(rmpt.Y * factor);
                        form.SetBounds(ampt.X - rmpt.X, ampt.Y - rmpt.Y, 
                        form.Width + intFunc(form.Width *  factor), 
                        form.Height + intFunc(form.Height *  factor));
                    });
                    return [form_mouseWheel];
                }

                function ShowImageBindDragMove(form, pic) {
                    var Cursors = forms.System.Windows.Forms.Cursors;
                    var ReleaseCapture = sp_config.GetType().Assembly.GetType("API").GetMethod("ReleaseCapture");

                    var pic_mouseMove = 
                    pic.MouseMove.connect(
                    function (sender, e) {
                        var hitResize = form.Height + form.Width - (e.X + e.Y) < 30;
                        var cursor = hitResize ? Cursors.SizeNWSE : Cursors.Default;
                        if (pic.Cursor != cursor) pic.Cursor = cursor;
                        if (e.Button == MouseButtons.Left) {
                            ReleaseCapture.Invoke(null, null);
                            sp.WindowFromHandle(form.Handle).SendMessageObj(0x0112,
                                hitResize ? 0xF008 : 0xF012, 0);
                        }
                        form.TopMost = true;
                    });

                    return [pic_mouseMove];
                }

                function FlushMemory()
                {
                    System.GC.Collect();
                    System.GC.WaitForPendingFinalizers();
                    if (System.Environment.OSVersion.Platform == System.PlatformID.Win32NT)
                        NativeModules.Kernel32.SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
                } 

                `
);


感谢分享
不过既然都分享到论坛了 不如也去github开个仓库存这些 可以造福更多人
分发上也便利

库建好了

怎么临时禁用?

点击右下角托盘s+图标,变灰手势不能用,但是在启动/退出脚本还运行

谢谢 各功能要导入哪个位置,还是不太懂。 比如:大写键监控、自动6s关闭大写 导入后可以显示红绿框,但是不会自动关

对,2#的大写键弹起了,提示不会关,只会红绿切换,代码我去掉了

使用7#的代码,提示会关