Page 1 of 2

Syntax for Funtion keys and key combos?

Posted: 28 Jun 2015, 16:10
by Titan99
Petr,
How can special keys, like F8, or Control-L be sent? Is there a syntax secret? Like {F8}?

I am using a Dynex keypad with AutoCad to speed drafting functions like so:

if (button == kb_add ) then lmc_send_keys('per ')
elseif (button == kb_minus ) then lmc_send_keys('\'orthoem ')
elseif (button == kb_multiply ) then lmc_send_keys('quickproperties ')
elseif (button == kb_divide ) then lmc_send_keys('line ')

Thank you for your LuaMacros routine!

Ed M.

Re: Syntax for Funtion keys and key combos?

Posted: 28 Jun 2015, 22:33
by Xupicor
Well, have a look at https://github.com/me2d13/luamacros/blo ... ndKeys.pas

Especially this:

Code: Select all

  SendKeyRecs : array[1..MaxSendKeyRecs] of TSendKey =
  (
   (Name:'BKSP';            VKey:VK_BACK),
   (Name:'BS';              VKey:VK_BACK),
   (Name:'BACKSPACE';       VKey:VK_BACK),
   (Name:'BREAK';           VKey:VK_CANCEL),
   (Name:'CAPSLOCK';        VKey:VK_CAPITAL),
   (Name:'CLEAR';           VKey:VK_CLEAR),
   (Name:'DEL';             VKey:VK_DELETE),
   (Name:'DELETE';          VKey:VK_DELETE),
   (Name:'DOWN';            VKey:VK_DOWN),
   (Name:'END';             VKey:VK_END),
   (Name:'ENTER';           VKey:VK_RETURN),
   (Name:'ESC';             VKey:VK_ESCAPE),
   (Name:'ESCAPE';          VKey:VK_ESCAPE),
   (Name:'F1';              VKey:VK_F1),
   (Name:'F10';             VKey:VK_F10),
   (Name:'F11';             VKey:VK_F11),
   (Name:'F12';             VKey:VK_F12),
   (Name:'F13';             VKey:VK_F13),
   (Name:'F14';             VKey:VK_F14),
   (Name:'F15';             VKey:VK_F15),
   (Name:'F16';             VKey:VK_F16),
   (Name:'F17';             VKey:VK_F17),
   (Name:'F18';             VKey:VK_F18),
   (Name:'F19';             VKey:VK_F19),
   (Name:'F2';              VKey:VK_F2),
   (Name:'F20';             VKey:VK_F20),
   (Name:'F21';             VKey:VK_F21),
   (Name:'F22';             VKey:VK_F22),
   (Name:'F23';             VKey:VK_F23),
   (Name:'F24';             VKey:VK_F24),
   (Name:'F3';              VKey:VK_F3),
   (Name:'F4';              VKey:VK_F4),
   (Name:'F5';              VKey:VK_F5),
   (Name:'F6';              VKey:VK_F6),
   (Name:'F7';              VKey:VK_F7),
   (Name:'F8';              VKey:VK_F8),
   (Name:'F9';              VKey:VK_F9),
   (Name:'HELP';            VKey:VK_HELP),
   (Name:'HOME';            VKey:VK_HOME),
   (Name:'INS';             VKey:VK_INSERT),
   (Name:'LEFT';            VKey:VK_LEFT),
   (Name:'NUM0';            VKey:VK_NUMPAD0),
   (Name:'NUM1';            VKey:VK_NUMPAD1),
   (Name:'NUM2';            VKey:VK_NUMPAD2),
   (Name:'NUM3';            VKey:VK_NUMPAD3),
   (Name:'NUM4';            VKey:VK_NUMPAD4),
   (Name:'NUM5';            VKey:VK_NUMPAD5),
   (Name:'NUM6';            VKey:VK_NUMPAD6),
   (Name:'NUM7';            VKey:VK_NUMPAD7),
   (Name:'NUM8';            VKey:VK_NUMPAD8),
   (Name:'NUM9';            VKey:VK_NUMPAD9),
   (Name:'NUMDECIMAL';      VKey:VK_DECIMAL),
   (Name:'NUMDIVIDE';       VKey:VK_DIVIDE),
   (Name:'NUMLOCK';         VKey:VK_NUMLOCK),
   (Name:'NUMMINUS';        VKey:VK_SUBTRACT),
   (Name:'NUMMULTIPLY';     VKey:VK_MULTIPLY),
   (Name:'NUMPLUS';         VKey:VK_ADD),
   (Name:'PGDN';            VKey:VK_NEXT),
   (Name:'PGUP';            VKey:VK_PRIOR),
   (Name:'PRTSC';           VKey:VK_PRINT),
   (Name:'RIGHT';           VKey:VK_RIGHT),
   (Name:'SCROLLLOCK';      VKey:VK_SCROLL),
   (Name:'TAB';             VKey:VK_TAB),
   (Name:'UP';              VKey:VK_UP)
  );
These names are recognized when put between curvy brackets {}, as per lines 270-318. Seems to work fine when tested.

Looking at the case statement (lines 220-333) you can see that the syntax is quite similar to the .NET SendKeys.Send(). That is - if you want to send Shift+a you write '+a', Alt+a is '%a', and Ctrl+a is '^a'.

Additionally there's '~' that is translated to VK_RETURN (ENTER key). There are also #, &, <, and > symbols used, which are a bit mysterious to me at the moment... Hopefully Petr will fill us in. :)

Re: Syntax for Funtion keys and key combos?

Posted: 29 Jun 2015, 07:37
by admin
In HidMacros download there's help rtf file describing syntax of sendkey command. LuaMacros use the same code. I should make it online, I know :-/.
Anyway it seems you have answered yourself or this syntax doesn't work in LuaMacros?

Re: Syntax for Funtion keys and key combos?

Posted: 29 Jun 2015, 07:52
by Xupicor
Thanks for the quick answer! Well, seems like it doesn't work as it should.

In Help.rtf there's this:
Surround sequences of characters or key names with parentheses in order to modify them as a group. For example, '+abc' shifts only 'a', while '+(abc)' shifts all three characters.
- however, '+(aaa)' returns Aaa, not AAA, (in LuaMacros) so there's something wrong with the grouping code. As in - in lines 696-719 there's nothing that would make the shift/alt/ctrl code aware of the groups.

Re: Syntax for Funtion keys and key combos?

Posted: 29 Jun 2015, 15:24
by admin
Thanks for testing :-), will have a look.

Re: Syntax for Funtion keys and key combos?

Posted: 29 Jun 2015, 17:25
by Xupicor
Well, one way to do it might be on finding opening '(' you could check the I-1 modifier (+/%/^), loop till closing ')' and apply it to every element. Then commence with I+1.

That would mean we couldn't do %^+(AAA) to have "Ctrl+Alt+Shit+A Ctrl+Alt+Shit+A Ctrl+Alt+Shit+A", but we can't have that at the moment either, right? I mean, even with single keys. It could be changed though, if instead of just checking the preceding modifier you'd loop through preceding modifiers. Heck, on finding a modifier you might check if preceding elements weren't modifiers too, and apply all of them to the next element. Then we could have Ctrl+Alt+Shit+A. ;)

Re: Syntax for Funtion keys and key combos?

Posted: 03 Dec 2015, 21:41
by clover
Hi!

Beginner with no programming skill here. Could anyone of you help me in the syntax for scripting in luamacro. :) :)

What I need is to have a button function the same as when I press the F11 function key.
This is what I have for the syntax so far

elseif (button == 106) then lmc_send_keys ('F11')

But all it does is print out f11. :(

Thank you!!

Re: Syntax for Funtion keys and key combos?

Posted: 04 Dec 2015, 09:09
by admin
Try lmc_send_keys ('{F11}')

Re: Syntax for Funtion keys and key combos?

Posted: 08 Dec 2015, 14:54
by clover
impossible!!! it works! :D :D
thank you! i had the darn-est time trying out diff. combos /[{"\' and etc. and couldn't not figure out the syntax for it.
May I ask for links to reference to learn the code?

Thank you for the swift reply! :D

Re: Syntax for Funtion keys and key combos?

Posted: 09 Dec 2015, 09:14
by admin
I know it's poorly documented :-/
There's some reference in Hidmacro help file, syntax is the same. I should make it available online, I know...