Win32::Shortkeys - A shortkeys perl script for windows
0.03
use Win32::Shortkeys; my $s = Win32::Shortkeys->new("kbhook.properties"); $s->run;
Depending on the the sorkeys.xml file, some keystroke are replaced with string or keys command (enter, tab, cursor right ...) taken from this file.
Since the synopsis above is short, the main things to describe are in the file pass to Win32::Shortkeys-new($file)>.
Win32::Shortkeys-
It must follow the Config::YAML::Tiny syntax. Mine looks like
file_path: shortkeys_utf8.xml file_encoding: UTF8 use_ctrl_v: 1 load_key: VK_HOME quit_key: VK_F12 usleep_delay: 400_000 vkcode_map: t: VK_TAB e: VK_RETURN d: VK_DOWN l: VK_LEFT r: VK_RIGHT x: VK_BACK s: VK_SHIFT c: VK_CONTROL a: VK_MENU w: VK_SPACE h: VK_HOM
The key given in the load_key property is used to reload the shorkeys.xml file (without exiting the script). The key given in the quit_key property is used to terminate the script.
It's name is given by the file_path property. It's xml syntax is:
file_path
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE shortkey SYSTEM "dtd/shk.dtd"> <shortkey> <data k='t'>Recent advances in biochemical and molecular diagnostics for the rapid detection of antibiotic-resistant Enterobacteriaceae: a focus </data> <data k='j'>Expert Review of Molecular Diagnostics </data> .... </shortkey>
The values of the k attribute are a-z string composed of lower case character(s) (a string can have two or more characters). I call those strings shortkeys and when press on the keyboard after they < key with the script running, the key pressed are replaced by the content of the corresponding data element.
For example, with the cursor in an opened notepad file, hitting the two keys <j when the script is running will replace this two characters with the value of the corresponding <data> element: Expert Review of Molecular Diagnostics.
The shortkeys.xml file should be utf-8 encoded, even if the encoding can be defined in the properties.
With the key <, the script enter a "search mode" for a shortkey sequence. This key is hard coded and can't be changed (unless you edit the code).
The text from the shortkeys file is sent to the keyboard using the send_input API function. With using the use.ctrl_v='1' attribute in a data element, the text will be place in the clipboard and paste (with sending the keys ctlr + v) at the cursor position.
use.ctrl_v='1'
<data k= 'a' use.ctrl_v= '1'> This text will be copied and paste. And the new line will be preserved. </data>
In the xml file, data elements can be combine using a dataref element.
<data k='qu'>10.1080/14737159.2017.1289087</data> <data k= 'u'> Published version; http://dx.doi.org/<dataref id= 'qu'></dataref> </data>
When hitting <u, the text that will be subtitued will be Published version; http://dx.doi.org/10.1080/14737159.2017.1289087
a command keystroke start with # (to diplay # as a character, it has to be enter has ##), next you have to give
the command itself, set by a character (only one character) listed in the map defined with the property vkcode_map
vkcode_map: t: VK_TAB e: VK_RETURN ...
The character z is hardcoded to indicate a waiting time : in the shortkeys_utf8.xml file #z04 will calls the code
#z04
usleep ( 4 * 100_000 );
If z is used to indicate a key in vkcode_map, this will be overriden.
how much you want to repeat that command, on two position, with a padding 0 if necessary (01)
the next characters are treated as text (unless a new command keystroke is defined with #)
The shift, control and alt keys are released
after a non-command key has been given. For example ctr+shift+a (written as #c01#s01a) will send the following event: key press for the keys control and shift, key press and released for the a key, key release for shift and control
at the end of a command keystroke, if the keys have not been released. For example a sequence of shit+tab, shift+tab, shift+tab (#s01#t01#t01#t01) will release the shift key at the end. On the contrary #s01#t01#t01#t01abc will call three back tab and will write Abc.
To install this module type the following:
perl Makefile.PL make make test make install
On windows use nmake or dmake instead of make.
The following modules are required in order to use this module
Test::Simple => 0.44, Win32::Shortkeys::Kbh => 0.01, Config::YAML::Tiny => 1.42, Win32::Clipboard => 0.58, XML::Parser => 2.44, Encode => 2.84, Time::HiRes => 1.9733, Carp => 1.40
Win32::Shortkeys::Ripper
Win32::Shortkeys::Kbh
Any questions or problems can be posted to me (rappazf) on my gmail account.
The current state of the source can be extract using Mercurial from
http://sourceforge.net/projects/win32-shortkeys/.
François Rappaz <rappazf@gmail.com>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
To install Win32::Shortkeys, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Win32::Shortkeys
CPAN shell
perl -MCPAN -e shell install Win32::Shortkeys
For more information on module installation, please visit the detailed CPAN module installation guide.