Win32-Shortkeys

 view release on metacpan or  search on metacpan

lib/Win32/Shortkeys.pm  view on Meta::CPAN

  $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.

=head1 DESCRIPTION

Since the synopsis above is short, the main things to describe are in the file pass to C<Win32::Shortkeys->new($file)>.

=head2 Properties file

It must follow the Config::YAML::Tiny syntax. Mine looks like

    file_path: shortkeys_utf8.xml
    file_encoding: UTF-8
    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.

=head2 The xml file

It's name is given by the C<file_path> property.
It's xml syntax is:

    <?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 C<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...

    <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

=head2 Commands syntax in shortkey.xml

=over 

=item * a command keystroke start with  # (to diplay # as a character, it has to be enter has ##), next you have to give

=item * 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 C<#z04>
will calls the code

    usleep ( 4 * 100_000 );

If z is used to indicate a key in vkcode_map, this will be overriden.

=item * how much you want to repeat that command,  on two position, with a padding 0 if necessary (01)

=item * the next characters are treated as text (unless a new command keystroke is defined with #)

=item * The shift, control and alt keys are released 

=over
            
=item * 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

=item * 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...

=back
  
=back    

=head1 INSTALLATION

To install this module type the following:

	perl Makefile.PL
	make
	make test
	make install



( run in 2.779 seconds using v1.01-cache-2.11-cpan-84e82930d8c )