{"id":2364,"date":"2021-05-21T19:58:05","date_gmt":"2021-05-21T10:58:05","guid":{"rendered":"https:\/\/yuis-programming.com\/?p=2364"},"modified":"2021-05-21T19:58:09","modified_gmt":"2021-05-21T10:58:09","slug":"node-js%e3%81%a7autohotkey%e3%82%92%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%86%e3%82%a3%e3%83%b3%e3%82%b0%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/yuis-programming.com\/?p=2364","title":{"rendered":"Node.js\u3067AutoHotkey\u3092\u30b9\u30af\u30ea\u30d7\u30c6\u30a3\u30f3\u30b0\u3059\u308b"},"content":{"rendered":"<p>Node.js\u3067Autohotkey\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u66f8\u3051\u308b\u3068\u3001\u4ed6\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3001\u4f8b\u3048\u3070\u30a6\u30a7\u30d6\u30b5\u30fc\u30d0\u30fc\u306eExpress.js\u3084\u3001WebSocket\u306a\u3069node.js\u306e\u4fbf\u5229\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3068\u7d71\u5408\u3057\u3066\u3001<br \/>\n\u30d5\u30ec\u30ad\u30b7\u30d3\u30ea\u30c6\u30a3\u306e\u9ad8\u3044\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306f\u4e0b\u8a18\u306e\u95a2\u6570\u3092\u5b9a\u7fa9\u3057\u3066\u304b\u3089\u5b9f\u884c\u3067\u304d\u308b\u30b3\u30fc\u30c9\u306e\u4f8b\u3067\u3059\u3002<br \/>\n\u3053\u306e\u30b3\u30fc\u30c9\u3067\u306f\u30b7\u30f3\u30d7\u30eb\u306b\u3001\u30de\u30a6\u30b9\u30af\u30ea\u30c3\u30af\u3092\u3057\u3066\u2192&#8221;hoge hoge&#8221;\u3068\u30ad\u30fc\u30dc\u30fc\u30c9\u30bf\u30a4\u30d4\u30f3\u30b0\u3059\u308b\u3001\u3068\u3044\u3046\u52d5\u4f5c\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-js\">await ahk({program: `MouseClick, left`});\nawait ahk({program: `send, hoge hoge`});\n<\/code><\/pre>\n<p>\u4eca\u56de\u306f\u7279\u306b\u3053\u308c\u3068\u3044\u3063\u305fnode.js\u306e\u305f\u3081\u306eautohotkey\u30e9\u30c3\u30d1\u30fc\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3046\u3001\u3068\u3044\u3063\u305f\u3053\u3068\u306f\u305b\u305a\u3001\u30b7\u30f3\u30d7\u30eb\u306b\u624b\u8efd\u306b\u4f7f\u3048\u308b\u95a2\u6570\u3092\u5b9a\u7fa9\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306f\u8efd\u304f\u66f8\u3044\u3066\u307f\u305f\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<pre><code class=\"language-js\">\nconst fs = require('fs');\nconst exec = require('child_process').exec;\n\n\/\/ ..\n\nasync function ahk(...arg)\n{\n  fs.writeFileSync(`.\/tmp.ahk`, `\n    #include C:\/pg\/autohotkey\/ahkrc.ahk\n\n    ${arg[0].program}\n\n    file := FileOpen(\"C:\/pg\/autohotkey\/.is_finished\", \"w\", \"UTF-8\") ; wait for ahk finish\n    file.Write(\"0\")\n    file.Close()\n  `);\n  await exec(\"nkf --overwrite --oc=UTF-8-BOM .\/tmp.ahk\", (error, stdout, stderr) =&gt; { if ( error ){ console.log(error) } if ( stdout ){ console.log(stdout) } if ( stderr ){ console.log(stderr) } });\n  await exec(\"AutoHotkeyU64.exe .\/tmp.ahk &amp;\", (error, stdout, stderr) =&gt; { if ( error ){ console.log(error) } if ( stdout ){ console.log(stdout) } if ( stderr ){ console.log(stderr) } });\n\n  await (new Promise((resolve) =&gt; {\n    fs.watch('\/mnt\/c\/pg\/autohotkey\/.is_finished', (e, f) =&gt; { resolve() })\n  })); \/\/ wait for ahk finish\n}\n<\/code><\/pre>\n<p>&#8220;C:\/pg\/autohotkey&#8221;\u30d1\u30b9\u3092\u9069\u5f53\u306a\u30d5\u30a9\u30eb\u30c0\u30d1\u30b9\u306b\u5909\u66f4\u3057\u3066\u4f7f\u7528\u3057\u307e\u3059\u3002<br \/>\n&#8220;ahkrc.ahk&#8221;\u306f\u5e38\u306b\u8aad\u307f\u8fbc\u3080autohotkey\u30b9\u30af\u30ea\u30d7\u30c8\u3001\u4f8b\u3048\u3070\u95a2\u6570\u306a\u3069\u3001\u306e\u30d5\u30a1\u30a4\u30eb\u3067\u3059\u3002\u4e0d\u5fc5\u8981\u306a\u5834\u5408\u306f\u30b3\u30e1\u30f3\u30c8\u30a4\u30f3\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>&#8220;nkf&#8221;\u30b3\u30de\u30f3\u30c9\u3067\u306e\u30d5\u30a1\u30a4\u30eb\u306e\u6587\u5b57\u30b3\u30fc\u30c9\u5909\u66f4\u306f\u3001autohotkey\u30b9\u30af\u30ea\u30d7\u30c8\u306b\u65e5\u672c\u8a9e\u6587\u5b57\u5217\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u3088\u3046\u306a\u5834\u5408\u306b\u63a8\u5968\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u306a\u304a\u3001nkf\u30b3\u30de\u30f3\u30c9\u306fWindows 10\u306eWSL Bash\u4e0a\u3067node.js\u3092\u52d5\u304b\u3057\u3066\u3044\u308b\u3053\u3068\u3092\u60f3\u5b9a\u3057\u3066\u4f7f\u308f\u308c\u3066\u3044\u307e\u3059\u3002Powershell\u306a\u3069\u304b\u3089node.js\u3092\u52d5\u304b\u3057\u3066\u3044\u308b\u3088\u3046\u306a\u5834\u5408\u306f\u3001&#8221;nkf&#8221;\u3092chochocolatey\u306a\u3069\u3067windows\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u304b\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30de\u30f3\u30c9\u3067WSL\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u3067\u304a\u305d\u3089\u304f\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre><code>bash -c \"nkf --overwrite --oc=UTF-8-BOM .\/tmp.ahk\"\n<\/code><\/pre>\n<p>&#8220;AutoHotkeyU64.exe&#8221;\u30d5\u30a1\u30a4\u30eb\u306e\u30d5\u30a9\u30eb\u30c0\u306b\u306f\u30d1\u30b9\u3092\u901a\u3057\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u30d5\u30a9\u30eb\u30c0\u3078\u306e\u30d1\u30b9\u306f\u4ee5\u4e0b\u306e\u306f\u305a\u3067\u3059\u3002<\/p>\n<pre><code>C:\\Program Files\\AutoHotkey\\AutoHotkeyU64.exe\n<\/code><\/pre>\n<p>\u30d1\u30b9\u3092\u901a\u3057\u305f\u304f\u306a\u3044\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u3067\u304a\u305d\u3089\u304f\u4ee3\u66ff\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><code>powershell.exe 'C:\\Program` Files\\AutoHotkey\\AutoHotkeyU64.exe .\/tmp.ahk'\n<\/code><\/pre>\n<p>\u3053\u306e\u95a2\u6570\u306e\u57fa\u672c\u7684\u306a\u69cb\u9020\u306f\u3001\u5358\u7d14\u306b\u3001fs.writeFileSync\u3067ahk\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3001exec\u3067\u305d\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u3001\u3068\u3044\u3046\u30b7\u30f3\u30d7\u30eb\u306a2\u30b9\u30c6\u30c3\u30d7\u3067\u3059\u304c\u3001<br \/>\n\u3053\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u306f\u3001autohotkey\u306e\u52d5\u4f5c\u306e\u7d42\u4e86\u3092<code>await<\/code>\u3067\u5f85\u6a5f\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u4ed5\u7d44\u307f\u3068\u3057\u3066\u3001\u4ee5\u4e0b\u306eahk\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u6700\u5f8c\u306b\u5b9f\u884c\u3057\u3001\u4e00\u6642\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre><code>file := FileOpen(\"C:\/pg\/autohotkey\/.is_finished\", \"w\", \"UTF-8\") ; wait for ahk finish\nfile.Write(\"0\")\nfile.Close()\n<\/code><\/pre>\n<p>\u4e00\u65b9\u3001node.js\u5074\u3067\u306f\u3001\u4e00\u6642\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\u30a2\u30af\u30b7\u30e7\u30f3\u304c\u3055\u308c\u308b\u3053\u3068\u3001\u3059\u306a\u308f\u3061ahk\u30b9\u30af\u30ea\u30d7\u30c8\u304c\u6700\u5f8c\u307e\u3067\u5b9f\u884c\u3055\u308c\u305f\u3053\u3068\u3001\u3092\u78ba\u8a8d\u3057\u3001\u305d\u306e\u5f8c\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3078\u7d9a\u304d\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-js\">await (new Promise((resolve) =&gt; {\n    fs.watch('\/mnt\/c\/pg\/autohotkey\/.is_finished', (e, f) =&gt; { resolve() })\n}));\n<\/code><\/pre>\n<p>\u3053\u308c\u306b\u3088\u308a\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3067\u306f\u3001\u30af\u30ea\u30c3\u30af\u304c\u5b9f\u884c\u3055\u308c\u305a\u306b&#8221;hoge hoge&#8221;\u304c\u30bf\u30a4\u30d4\u30f3\u30b0\u3055\u308c\u3066\u3057\u307e\u3046\u306e\u306b\u5bfe\u3057\u3001<\/p>\n<pre><code class=\"language-js\">ahk({program: `MouseClick, left`}); \/\/ this does not wait the ahk program finish, thus, the text will be sent before the left click\nahk({program: `send, hoge hoge`});\n<\/code><\/pre>\n<p><code>await<\/code>\u3067\u7d42\u4e86\u3092\u5f85\u6a5f\u3057\u3066\u305d\u308c\u305e\u308c\u306eautohotkey\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u9806\u6b21\u5b89\u5b9a\u7684\u306b\u5b9f\u884c\u3057\u3066\u3044\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-js\">await ahk({program: `MouseClick, left`}); \/\/ this does work perfectly\nawait ahk({program: `send, hoge hoge`});\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Node.js\u3067Autohotkey\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u66f8\u3051\u308b\u3068\u3001\u4ed6\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3001\u4f8b\u3048\u3070\u30a6\u30a7\u30d6\u30b5\u30fc\u30d0\u30fc\u306eExpress [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[],"acf":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8Rxwo-C8","_links":{"self":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts\/2364"}],"collection":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2364"}],"version-history":[{"count":1,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts\/2364\/revisions"}],"predecessor-version":[{"id":2365,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts\/2364\/revisions\/2365"}],"wp:attachment":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}