DAILY DOCDAILY DOC
Rust
Node
Notes
Ubuntu
Leetcode
  • it-tools
  • excalidraw
  • linux-command
Rust
Node
Notes
Ubuntu
Leetcode
  • it-tools
  • excalidraw
  • linux-command
  • BFC 块级格式化上下文
  • Note
  • WebAssembly
  • public api
  • 位运算
  • bitwise operator
  • css实现隐藏效果
  • css snippets
  • 抖音点赞
  • js 相等判断
  • fetch ReadableStream
  • git
  • Github Actions 工作流
  • google search
  • RPC vs HTTP
  • gravatar
  • hhkb
  • Init project
  • input 文件上传
  • mac

    • Mac 使用技巧
    • alfred
    • mac shortcuts
    • shortcuts text edit
    • mac 修改host
  • 微前端
  • mock
  • nginx dump
  • nginx
  • NirCmd
  • npm
  • Operator Precedence
  • package.json
  • url query 解析
  • pnpm
  • JavaScript Precise countdown
  • react 模版
  • regexp
  • setup web development
  • telegram

    • telegram bot
  • timeFunction ease
  • 视频裁剪
  • vscode

    • vscode 高级指南
    • bracketPairs
    • jsconfig.json
    • vscode pipe into code
    • social project
    • vscode tasks
  • draggable resizable
  • windows 激活
  • 前端截图实现
  • 文本配音 富文本实现
  • 图片处理
  • 前端坐标
  • 定时任务
  • work efficient
  • 微信小程序动画实现方案
  • 排列组合
  • 数列
  • 语音驱动文字
  • 浏览器
  • 状态管理
  • 移动盒子
  • 移动端开发常用snippets
  • 设计模式
  • web performance

NirCmd

是一个小型的命令行实用程序,允许您执行各种系统任务和自动化任务。它是由 NirSoft 提供的免费工具。以下是 NirCmd 能够执行的一些操作:

文件和文件夹操作

  • 创建、删除、复制、移动文件或文件夹:
    nircmd.exe copyfile "source.txt" "destination.txt"
    nircmd.exe deletefile "file.txt"
    nircmd.exe createdir "C:\NewFolder"
    

系统操作

  • 关机、重启、注销系统:
    nircmd.exe exitwin poweroff
    nircmd.exe exitwin reboot
    nircmd.exe exitwin logoff
    

窗口操作

  • 最小化、最大化、关闭窗口:

    nircmd.exe win min title "Calculator"
    nircmd.exe win max class "Notepad"
    nircmd.exe win close ititle "Untitled - Notepad"
    
  • 获取窗口句柄和其他信息:

    nircmd.exe win gethandle title "Calculator"
    

音频操作

  • 调整音量、静音:
    nircmd.exe mutesysvolume 1
    nircmd.exe changesysvolume -5000
    

系统环境操作

  • 设置环境变量:
    nircmd.exe setenv "MyVariable" "MyValue"
    

鼠标和键盘操作

  • 移动鼠标、点击鼠标、发送键盘按键:
    nircmd.exe setcursor 100 200
    nircmd.exe sendmouse left click
    nircmd.exe sendkeypress enter
    

显示操作

  • 关闭、打开显示器:
    nircmd.exe monitor off
    nircmd.exe monitor on
    

剪贴板操作

  • 复制、清空剪贴板:
    nircmd.exe clipboard save "clipboard.txt"
    nircmd.exe clipboard clear
    

系统信息

  • 显示系统信息、弹出对话框:
    nircmd.exe sysinfo
    nircmd.exe infobox "Hello, World!" "NirCmd"
    

捕获屏幕截图

  • 截取屏幕并保存为文件:
    nircmd.exe savescreenshot "screenshot.png"
    nircmd.exe savescreenshotfull "screenshot.png"
    

示例:使用 NirCmd 在 Electron 中截取窗口截图

假设你想截取一个窗口的截图,并在 Electron 中使用该截图进行进一步处理,可以按照以下步骤进行:

1. 下载 NirCmd 并放置在项目目录中

确保 nircmd.exe 在你的项目目录或系统路径中。

2. 使用 Node.js 运行 NirCmd 命令

const { exec } = require('child_process');
const path = require('path');

const nircmdPath = path.join(__dirname, 'nircmd.exe');
const windowTitle = 'Calculator'; // 替换为目标窗口的标题
const screenshotPath = path.join(__dirname, 'screenshot.png');

// 截取指定窗口的截图
exec(`${nircmdPath} win -name ${windowTitle} savescreenshot ${screenshotPath}`, (err, stdout, stderr) => {
    if (err) {
        console.error(`Error taking screenshot: ${err}`);
        return;
    }
    console.log(`Screenshot saved to ${screenshotPath}`);
    // 在此处添加处理截图的逻辑,例如在 Electron 应用中显示截图
});

使用 NirCmd 工具在 Windows 上模拟鼠标按下并拖动到指定位置可以通过以下步骤实现。NirCmd 是一款小巧的命令行工具,能够执行许多与系统操作相关的任务,包括模拟键盘和鼠标操作。

安装 NirCmd

  1. 下载 NirCmd:

    • 访问NirSoft 官方网站。
    • 下载 NirCmd 压缩包并解压缩到一个目录。
  2. 将 NirCmd 目录添加到系统的 PATH 环境变量中,方便在命令行中直接调用nircmd命令。

使用 NirCmd 模拟鼠标操作

你可以使用以下命令来模拟鼠标按下和拖动操作:

  1. 模拟鼠标按下:

    nircmd.exe sendmouse left down
    
  2. 移动鼠标到指定位置:

    nircmd.exe setcursor 500 500
    

    这里的500 500是屏幕坐标,你可以根据需要调整。

  3. 模拟鼠标释放:

    nircmd.exe sendmouse left up
    

windows 实现按下拖动

为了实现鼠标按下并拖动到指定位置,可以组合上述命令。例如,以下脚本将模拟鼠标按下、移动到指定位置并释放:

@echo off
:: 鼠标按下
nircmd.exe sendmouse left down

:: 移动鼠标到新位置
nircmd.exe setcursor 500 500

:: 等待一段时间
timeout /t 1 /nobreak

:: 鼠标释放
nircmd.exe sendmouse left up

解释

  1. sendmouse left down:模拟鼠标左键按下。
  2. setcursor 500 500:将鼠标光标移动到屏幕上的(500, 500)位置。
  3. timeout /t 1 /nobreak:等待 1 秒,确保移动操作完成。
  4. sendmouse left up:模拟鼠标左键释放。

调整和扩展

  • 等待时间:根据需要调整timeout的时间,以适应不同的拖动距离和速度。
  • 坐标:调整setcursor命令中的坐标,拖动到不同的位置。
  • 组合其他 NirCmd 命令:根据需要添加其他 NirCmd 命令以实现更多操作。

通过以上步骤和示例,你可以使用 NirCmd 在 Windows 上实现按下鼠标并拖动到指定位置的操作。

Last Updated:
Contributors: rosendo
Prev
nginx
Next
npm