Keyboard macros: Difference between revisions

m
(Added Wren)
m (→‎{{header|Wren}}: Minor tidy)
 
(One intermediate revision by one other user not shown)
Line 8:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">Loop, 200 ; loop 200 times while not paused
{
TrayTip, counting, %A_Index% press alt-p to pause
Line 32:
TrayTip, resume, resuming, 2
Pause, off
}</langsyntaxhighlight>
See [http://www.autohotkey.com/forum/topic44290.html&highlight=vim ahk-viper-mode] for a context sensitive vi key bindings example.
 
=={{header|BBC BASIC}}==
===Native===
<langsyntaxhighlight lang="bbcbasic"> *KEY 1 |!|A
*KEY 2 |!|B
REPEAT
Line 54:
DEF PROCmethod2
PRINT "You pressed F2"
ENDPROC</langsyntaxhighlight>
===Windows===
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> FVIRTKEY = 1
VK_F1 = &70
VK_F2 = &71
Line 89:
DEF PROCmethod2
PRINT "You pressed F2"
ENDPROC</langsyntaxhighlight>
 
=={{header|C}}==
Line 95:
 
The following example grabs Alt+F6 and Alt+F7 system-wide on a X server.
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
Line 132:
}
return EXIT_SUCCESS;
}</langsyntaxhighlight>
 
=={{header|Clojure}}==
Line 138:
 
The following example is at application level, printing out what key was pressed:
<langsyntaxhighlight lang="clojure">
(ns hello-seesaw.core
(:use seesaw.core))
Line 149:
pack!
show!)))
</syntaxhighlight>
</lang>
 
=={{header|Delphi}}==
Version Console Application
<syntaxhighlight lang="delphi">
<lang Delphi>
program Key_Bindings_test;
 
Line 276:
readln;
end.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 289:
=={{header|EchoLisp}}==
The '''(meta-key "key-value" "bound-string")''' function binds a modifier+key keypress to a string or function call.
<langsyntaxhighlight lang="lisp">
;; see initial bindings : GREEK DICTIONARY
(meta-keys) → (("0" "❌") ("1" "❗️") ("2" "❓") ("3" "✔️") ("4" "⛔️") ("5" "✅") ("6" "🚩") ("7" "⌚️")
Line 306:
(meta-key "A" "Antoinette") ; string
(meta-key "H" "(begin (writeln 'HELLO) (date 'today))") ; function call
</syntaxhighlight>
</lang>
 
=={{header|Go}}==
Line 315:
 
Note also that if you pass 'nil' to the XOpenDisplay function, it defaults to the value of the DISPLAY environment variable which has to be in a certain format to enable a connection to the X server to be established - check [https://www.x.org/releases/X11R7.7/doc/libX11/libX11/libX11.html the documentation] for details.
<langsyntaxhighlight lang="go">package main
 
/*
Line 372:
fmt.Println("XOpenDisplay did not succeed")
}
}</langsyntaxhighlight>
 
=={{header|HicEst}}==
<langsyntaxhighlight lang="hicest">! bound to application
CALL F2
! ...
Line 396:
! Fn is suspended if m > n AND n <= 5, else Fm is queued
! ...
END</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
 
This is application-specific and works in both languages:
<langsyntaxhighlight lang="unicon">
global kMap
 
Line 422:
procedure italicsOff()
return "<\\i>"
end</langsyntaxhighlight>
 
Sample run:
Line 432:
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">
package keybord.macro.demo;
 
Line 463:
}
}
</syntaxhighlight>
</lang>
 
=={{header|JavaScript}}==
The example below captures the F7 key when pressed, if the document (that is, the web page) has focus. If the function returns ''false'', the event processing is halted. If it returns any other value, including ''undefined'', the event continues up the DOM tree ('bubbling').
 
<langsyntaxhighlight lang="javascript">document.onkeydown = function(evt) {
if (evt.keyCode === 118) {
alert("You pressed F7!");
return false;
}
}</langsyntaxhighlight>
 
See [http://www.quirksmode.org/js/keys.html quirksmode] for more information about key detection in JavaScript.
Line 479:
=={{header|Julia}}==
Macros are within the Gtk window.
<langsyntaxhighlight lang="julia">using Gtk
 
function keypresswindow()
Line 501:
 
keypresswindow()
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.2.31
 
import javax.swing.JFrame
Line 529:
isVisible = true
}
}</langsyntaxhighlight>
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckIt {
\\ Scan statement exist from version 1
Line 564:
}
Checkit
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Map the keystroke t to a simple script
<langsyntaxhighlight Mathematicalang="mathematica">SetOptions[EvaluationNotebook[], NotebookEventActions -> {{"KeyDown", "t"} :> Print["You pressed \"t\""]}]</langsyntaxhighlight>
 
=={{header|Nim}}==
{{libheader|gintro}}
As we need to catch the key press events, we give an example inside a Gtk3 application.
<langsyntaxhighlight Nimlang="nim">import tables
 
import gintro/[glib, gobject, gio]
Line 647:
let app = newApplication(App, "Rosetta.KeyboardMacros")
discard app.connect("activate", activate)
discard app.run()</langsyntaxhighlight>
 
=={{header|Oz}}==
Window-specific key bindings:
<langsyntaxhighlight lang="oz">declare
[QTk] = {Module.link ['x-oz://system/wp/QTk.ozf']}
Label
Line 664:
action:toplevel#close
)}
{Window show}</langsyntaxhighlight>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use Term::ReadKey;
Line 705:
}
 
ReadMode 0; # reset the terminal to normal mode</langsyntaxhighlight>
 
=={{header|Phix}}==
Line 714:
a general key handler.
Obviously K_C and K_F2 could be swapped without any problem.
<!--<langsyntaxhighlight Phixlang="phix">-->
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 744:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</langsyntaxhighlight>-->
 
===system===
Line 754:
of "keyboard macros" - though of course you could easily replace that
SendInput call with any routine of your choosing.
<!--<langsyntaxhighlight Phixlang="phix">-->
<span style="color: #000080;font-style:italic;">--
-- demo\arwendemo\hotkey.exw
Line 899:
<span style="color: #000000;">WinMain</span><span style="color: #0000FF;">(</span><span style="color: #000000;">Main</span><span style="color: #0000FF;">,</span><span style="color: #000000;">SW_NORMAL</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
 
=={{header|PicoLisp}}==
Line 906:
global variable, 'Up' and 'Down' arrows to increment or decrement that value,
and 'Home' to print the current value to the console.
<langsyntaxhighlight PicoLisplang="picolisp">(load "@lib/led.l" "@lib/term.l")
 
(fkey *XtF1
Line 918:
 
(fkey *XtHome
(prinl "Current value is " *Number) )</langsyntaxhighlight>
Output when hitting 'F1', 'Down', 'Up', 'Up' and 'Home':
<pre>Initialized value to 1
Line 929:
PureBasic has support for shortcut/macro creation in any window that supports events. This allows for creation of both single and combinations as shown in the code below.
For full set of combinations on PC, Mac & Linux please see the official manual, [http://www.purebasic.com/documentation/window/addkeyboardshortcut.html here].
<langsyntaxhighlight PureBasiclang="purebasic">#Win = 0
#Demo1 = 0
#Demo2 = 1
Line 954:
EndSelect
ForEver
EndIf</langsyntaxhighlight>
 
=={{header|Python}}==
Works on Unix platforms.
 
<langsyntaxhighlight lang="python">#!/usr/bin/env python
import curses
 
Line 980:
curses.echo()
curses.endwin()
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
 
<langsyntaxhighlight lang="racket">
#lang racket
 
Line 1,039:
macros '())]
[else (write-byte b) (flush-output) (loop inps v '())])))))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>my $TTY = open("/dev/tty");
my @INPUT;
 
Line 1,089:
default { log "Unrecognized key: $_"; }
}
}</langsyntaxhighlight>
 
=={{header|REBOL}}==
<langsyntaxhighlight REBOLlang="rebol">REBOL [
Title: "Keyboard Macros"
URL: http://rosettacode.org/wiki/Keyboard_macros
Line 1,119:
pad 1x100 return
text "(c) 1977 G. Beker"
]</langsyntaxhighlight>
 
=={{header|REXX}}==
Line 1,130:
<br><br>REXX programs not included are '''$T''' which is only used when specific options are used (used when TOPS is specified),
<br>the '''$ERR''' program which issues errors, and '''$H''' which shows '''help''' and other documentation.
<langsyntaxhighlight lang="rexx">/*REXX program can re-define most keys (including F keys) on a PC keyboard.*/
trace off
parse arg !
Line 1,729:
syntax: !sigl=sigl; call er 13,!FID(2) !FID(3) !sigl !cal() condition('D') sourceline(!sigl)
whenstamp: arg whenFID; call lineout whenFID,strip(left(date('U'),6)left(date("S"),4) time() arg(2)); call lineout whenFID,' '; call lineout whenFID; return
</syntaxhighlight>
</lang>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "guilib.ring"
 
Line 1,756:
on 16777265 see "You pressed F2 " + nl
off
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,767:
Here's a sample from the Shoes manual showing how to capture key sequences. This is application specific.
 
<langsyntaxhighlight lang="ruby">Shoes.app do
@info = para "NO KEY is PRESSED."
keypress do |k|
@info.replace "#{k.inspect} was PRESSED."
end
end</langsyntaxhighlight>
 
A more specific example, using some emacs bindings
 
<langsyntaxhighlight lang="ruby">Shoes.app do
keypress do |key|
case key
Line 1,798:
end
end
end</langsyntaxhighlight>
 
=={{header|Scala}}==
===Java Swing Interoperability===
{{libheader|Scala Java Swing interoperability}}
<langsyntaxhighlight Scalalang="scala">import java.awt.event.{KeyAdapter, KeyEvent}
 
import javax.swing.{JFrame, JLabel, WindowConstants}
Line 1,826:
}
 
}</langsyntaxhighlight>
 
=={{header|Tcl}}==
{{libheader|Tk}}
All Tk bindings are bound to a context that is no wider than a particular application and is frequently smaller (e.g., a single dialog box or an individual widget).
<langsyntaxhighlight lang="tcl">package require Tk
# Show off some emacs-like bindings...
pack [label .l -text "C-x C-s to save, C-x C-c to quit"]
Line 1,838:
tk_messageBox -message "We would save here"
}
bind . <Control-x><Control-c> {exit}</langsyntaxhighlight>
===Key-to-key mapping macros===
A more direct macro-like facility (substituting one key sequence for another) would be:
<langsyntaxhighlight lang="tcl">bind . <F1> {
foreach c [split "Macro demo!" {}] {
event generate %W $c
}
}</langsyntaxhighlight>
This can then be wrapped up like this:
<langsyntaxhighlight lang="tcl">package require Tk
proc sendMacro {w string} {
foreach c [split $string {}] {
Line 1,862:
macro F2 "You pressed the F2 key"
macro F3 "I'm getting bored here..."
pack [text .t]; # A place for you to test the macros</langsyntaxhighlight>
 
=={{header|Vedit macro language}}==
<langsyntaxhighlight lang="vedit">// Configure a key to access menu item.
// The menu item may then contain the commands directly, or it may call a macro from disk.
// This has the advantage that the key binding is shown in the menu.
Line 1,883:
 
// Remove a key assignment. If INSERT option was used when the key was assigned, the old assignment will come in effect again.
Key_Delete("Ctrl-Shft-N")</langsyntaxhighlight>
 
=={{header|Wren}}==
Line 1,890:
<br>
As it's not currently possible for Wren-cli to access Xlib directly, we embed a Wren script in a C application to complete this task.
<langsyntaxhighlight ecmascriptlang="wren">/* keyboard_macrosKeyboard_macros.wren */
 
var GrabModeAsync = 1
Line 1,949:
xd.ungrabKey(xd.keysymToKeycode(X.stringToKeysym("F7")), Mod1Mask, drw)
xd.ungrabKey(xd.keysymToKeycode(X.stringToKeysym("F6")), Mod1Mask, drw)
xd.closeDisplay()</langsyntaxhighlight>
<br>
We now embed this Wren script in the following C program, compile and run it.
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Line 2,111:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "keyboard_macrosKeyboard_macros.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 2,127:
free(script);
return 0;
}</langsyntaxhighlight>
 
{{omit from|ACL2}}
9,476

edits