<astyle=margin-left:1px;margin-right:1px;display:inline-blockhref=https://minio.arsenm.dev/minio/kbdemu><imgstyle=height:18px;width:100pxsrc="https://img.shields.io/static/v1.svg?label=download&message=binary&color=blue"></a></p><p>This page assumes you have already installed KbdEmu. If not, follow the installation instructions on the installation page:</p><aclass=btnstyle=color:#fff;background-color:#357eddhref=../installation>Installation</a><h2id=scripts>Scripts<ahref=#scriptsclass=anchoraria-hidden=true>#</a></h2><p>KbdEmu uses <ahref=https://gitea.arsenm.dev/Arsen6331/scpt>scpt</a> as its scripting language. The example script for kbdemu looks like this:</p><pre><code>set testKey to "x"
keystroke $testKey with action "hold"
sleep "1s"
keystroke $testKey with action "release"
type "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
scroll 5 with direction "up"
click "right"
move-mouse [0, 0]
send-notification "Test"
beep
open-location "https://www.arsenm.dev/"
set showDetails to (display-dialog "Show details?" with type "yesno")
if $showDetails {
display-dialog {"Color: " + (pixel-color [100, 100]) + ", Mouse: " + (str (mouse-position))} with title "Details"
</code></pre><p>By default, the <code>kbdemu</code> command will look for and execute a file called <code>kbdemu.scpt</code>, but that can be changed using the <code>--file</code> flag.</p><hr><h2id=builtins>Builtins<ahref=#builtinsclass=anchoraria-hidden=true>#</a></h2><p>KbdEmu comes with some extra functions for automation</p><hr><h3id=numcpu><code>numcpu</code><ahref=#numcpuclass=anchoraria-hidden=true>#</a></h3><p>Returns the amount of available CPUs as a number.</p><p>Example:</p><pre><code>print (numcpu)
</code></pre><hr><h3id=sleep><code>sleep</code><ahref=#sleepclass=anchoraria-hidden=true>#</a></h3><p>Sleeps for a duration as specified by an unnamed string argument formatted according to the specification of golang’s <code>time.ParseDuration()</code>:</p><aclass=btnstyle=color:#fff;background-color:#00acd7href=https://golang.org/pkg/time#ParseDuration><spanclass="iconify icon:cib:go"></span>
</code></pre><hr><h3id=display-dialog><code>display-dialog</code><ahref=#display-dialogclass=anchoraria-hidden=true>#</a></h3><p>Displays a dialog window with the specified parameters.</p><p>Examples:</p><pre><code>display-dialog "Test1"
display-dialog "Test2" with title "Title Test"
print (display-dialog "Test3" with title "Entry Test" with type "entry")
</code></pre><p>These are all the supported dialog types:</p><ul><li>info</li><li>warning</li><li>error</li><li>entry</li><li>yesno</li></ul><p>Default dialog type is info.</p><hr><h3id=send-notification><code>send-notification</code><ahref=#send-notificationclass=anchoraria-hidden=true>#</a></h3><p>Sends a notification according to the specified parameters</p><p>Examples:</p><pre><code>send-notification "Test"
send-notification "Test" with title "Title"
send-notification "Test" with title "Title" with icon "test.png"
</code></pre><hr><h3id=beep><code>beep</code><ahref=#beepclass=anchoraria-hidden=true>#</a></h3><p>Creates a beep sound, if impossible, falls back to sending bell character.</p><p>Examples:</p><pre><code>beep
beep "3s"
</code></pre><hr><h3id=click><code>click</code><ahref=#clickclass=anchoraria-hidden=true>#</a></h3><p>Emulates a mouse click</p><p>Example:</p><pre><code>click "right"
</code></pre><hr><h3id=scroll><code>scroll</code><ahref=#scrollclass=anchoraria-hidden=true>#</a></h3><p>Scrolls the specifed amount in the specified direction</p><p>Example:</p><pre><code>scroll 5 with direction "up"
</code></pre><hr><h3id=move-mouse><code>move-mouse</code><ahref=#move-mouseclass=anchoraria-hidden=true>#</a></h3><p>Moves the cursor to the specified coordinates</p><p>Example:</p><pre><code>move-mouse [100, 200]
</code></pre><hr><h3id=keystroke><code>keystroke</code><ahref=#keystrokeclass=anchoraria-hidden=true>#</a></h3><p>Emulates a key event</p><p>Examples:</p><pre><code>keystroke "y" with action "hold"
sleep "2s"
keystroke "y" with action "release"
keystroke "x"
</code></pre><p>Default action is <code>tap</code> which presses and releases the key.</p><hr><h3id=type><code>type</code><ahref=#typeclass=anchoraria-hidden=true>#</a></h3><p>Types a string using the keyboard</p><p>Example:</p><pre><code>type "Hello, World"
</code></pre><hr><h3id=mouse-position><code>mouse-position</code><ahref=#mouse-positionclass=anchoraria-hidden=true>#</a></h3><p>Returns the current mouse position in the form of an array containing two number elements.</p><p>Example:</p><pre><code>print (mouse-position) # [0 0]
</code></pre><hr><h3id=pixel-color><code>pixel-color</code><ahref=#pixel-colorclass=anchoraria-hidden=true>#</a></h3><p>Returns a string containing the hex color of the given coordinates.</p><p>Example:</p><pre><code>print (pixel-color [100, 100]) # ffffff
</code></pre><hr><h3id=log><code>log</code><ahref=#logclass=anchoraria-hidden=true>#</a></h3><p>Logs the provided message at the given level.</p><p>Examples:</p><pre><code>log "Complete"
log "Error" with level "fatal"
</code></pre><p>The available levels are:</p><ul><li>info</li><li>debug</li><li>warn</li><li>fatal</li></ul><p>Default log level is info</p><hr><h3id=user-choice><code>user-choice</code><ahref=#user-choiceclass=anchoraria-hidden=true>#</a></h3><p>Displays a user choice dialog window with provided items, returns selected item.</p><p>Example:</p><pre><code>user-choice "Choose an option" with items ["Hello", "World", 1, 3.14159, 6.28318]
</code></pre><hr><h3id=open-location><code>open-location</code><ahref=#open-locationclass=anchoraria-hidden=true>#</a></h3><p>Opens given URL in the default application set to open it.</p><p>Examples:</p><pre><code>open-location "https://www.arsenm.dev"
open-location "/home"
</code></pre><hr><h2id=variables>Variables<ahref=#variablesclass=anchoraria-hidden=true>#</a></h2><p>KbdEmu exposes some variables for use in scripts.</p><hr><h3id=goos><code>$GOOS</code><ahref=#goosclass=anchoraria-hidden=true>#</a></h3><p>The value from golang’s <code>runtime.GOOS</code></p><aclass=btnstyle=color:#fff;background-color:#00acd7href=https://golang.org/pkg/runtime#GOOS><spanclass="iconify icon:cib:go"></span>
Godoc</a><hr><h3id=goarch><code>$GOARCH</code><ahref=#goarchclass=anchoraria-hidden=true>#</a></h3><p>The value from golang’s <code>runtime.GOARCH</code></p><aclass=btnstyle=color:#fff;background-color:#00acd7href=https://golang.org/pkg/runtime#GOARCH><spanclass="iconify icon:cib:go"></span>
Godoc</a><hr><h3id=arguments><code>$arguments</code><ahref=#argumentsclass=anchoraria-hidden=true>#</a></h3><p>Non-flag command line arguments provided to KbdEmu</p><p>Example:</p><p>Command:</p><divclass=highlight><preclass=chroma><codeclass=language-bashdata-lang=bash>kbdemu --file script.scpt <spanclass=s2>"Hello, World"</span>
</code></pre></div><p>Contents of <code>script.scpt</code>:</p><pre><code>print $arguments[0] # Hello, World