Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: jackhab on January 22, 2009, 04:15:56 pm

Title: Keyboard macros
Post by: jackhab on January 22, 2009, 04:15:56 pm
Is there any way to create keyboard macros in CB? The KeyMacs plug-in mentioned here and there on the forum is not available for download.
Title: Re: Keyboard macros
Post by: lgtnt on January 23, 2009, 12:57:15 pm
Is there any way to create keyboard macros in CB? The KeyMacs plug-in mentioned here and there on the forum is not available for download.
I want to know this also
Title: Re: Keyboard macros
Post by: ollydbg on January 23, 2009, 01:24:44 pm
Is there any way to create keyboard macros in CB? The KeyMacs plug-in mentioned here and there on the forum is not available for download.

Check on this plug-in during installation, it is off by default.
Title: Re: Keyboard macros
Post by: jackhab on January 26, 2009, 01:21:53 pm
Is there any way to create keyboard macros in CB? The KeyMacs plug-in mentioned here and there on the forum is not available for download.

Check on this plug-in during installation, it is off by default.

Sorry, it is not. I check in both 8.02 and SVN-5394 versions.
Title: Re: Keyboard macros
Post by: MortenMacFly on January 27, 2009, 07:23:55 am
Sorry, it is not. I check in both 8.02 and SVN-5394 versions.
You might want to compile C::B yourself - then you have the ultimate control about what you need/compile.
Title: Re: Keyboard macros
Post by: vix on February 10, 2009, 01:19:46 pm
Quote
You might want to compile C::B yourself - then you have the ultimate control about what you need/compile.

If there aren't particular problems, I think that including the KeyMacs plugin into the default Nightly builds would be helpful....
Anyway you can leave it disabled by default, but it'd be easy enabling it
Title: Re: Keyboard macros
Post by: Pecan on February 10, 2009, 02:43:55 pm
The KeyMacs plugin is not a part of CB. Compiling CB will not produce it for you.

It has not been updated or available for more than a year. It was never a part of the CB contrib plugins. It was offered but never accepted.

When it was made public, it was downloaded all of three times. Therefore not worth the high maintenance time to keep it current with CB changes.

Title: Re: Keyboard macros
Post by: MortenMacFly on February 11, 2009, 11:52:53 am
When it was made public, it was downloaded all of three times.
Hehe - one was me then. I don't maintain it - but my copy is still working with the up-to-date C::B.
Title: Re: Keyboard macros
Post by: vix on February 11, 2009, 01:31:10 pm
Quote
Hehe - one was me then. I don't maintain it - but my copy is still working with the up-to-date C::B.

Another one was me... and in the past (on my old PC) I was able to use it inside C::B
But now with the last Nightly Builds and my new PC the entry Plugins --> Key Macro has disappeared!!!
I simply copied the KeyMacs.dll to /share/codeblocks/plugins/ folder, and KeyMacs.zip to /share/codeblocks/ as I did in the past....
Is there something I missed?
Title: Re: Keyboard macros
Post by: Pecan on February 11, 2009, 01:43:40 pm

vix:

The plugin most probably needs to be re-compiled against the nightly dll so that it's symbols and addresses corellate with the nightly .dll or .so
Title: Re: Keyboard macros
Post by: vix on February 12, 2009, 08:37:19 am
Quote
The plugin most probably needs to be re-compiled against the nightly dll so that it's symbols and addresses corellate with the nightly .dll or .so

I opened the KeyMacs.cbp file (from KeyMacs 3.15.3) and simply press Build from my Nightly Build C::B
But I have a lot of error messages:
- sdk.h: No such file or directory
- configurationpanel.h: No such file or directory
- ...
Should I have also C::B source files on my PC to successfully recompile this plugin?
Title: Re: Keyboard macros
Post by: Jenna on February 12, 2009, 11:27:53 am
Should I have also C::B source files on my PC to successfully recompile this plugin?

Yes !
Title: Re: Keyboard macros
Post by: vix on February 12, 2009, 01:37:28 pm
Quote
Insert Quote
Quote from: vix on Today at 08:37:19 am
Should I have also C::B source files on my PC to successfully recompile this plugin?

Yes !

I tried downloading C::B source files and wxWidgets headers, but I didn't manage to recompile the plugin without errors  :x
Could MortenMacFly send me a compiled copy of the plugin working with the last C:B NB?

Thanks
Title: Re: Keyboard macros
Post by: Jenna on February 12, 2009, 01:44:27 pm
I tried downloading C::B source files and wxWidgets headers, but I didn't manage to recompile the plugin without errors  :x

You should in this case build C::B yourself (the actual trunk is not the same as used for the nightlies) and wxWidgets-headers are not enough, you also need the lib(s) to link against.

Did you read the Nighly Cookbook (http://wiki.codeblocks.org/index.php?title=Nightly_Cookbook)?
It tells you what you need to build C::B from source.
Title: Re: Keyboard macros
Post by: vix on February 19, 2009, 08:17:48 am
I successfully built C::B and the plugins in the contrib directory by myself.
Then I added the KeyMacs project (sources of the version 3.15.3 that is the last one I downloaded some months ago), and I had to do this changes to recompile it
- replace GetAppWindow() with GetAppFrame() in KeyMacs.cpp (I found this suggestion in the C::B forum)
- in the Build options... -> Search directories replace $(#cb)\sdk\wxscintilla\include with $(#cb.include)\wxscintilla\include
but I noticed that the Build command created a dll of 6870kB (the one shipped with the sources is 468kB

Is there something wrong?
Title: Re: Keyboard macros
Post by: MortenMacFly on February 19, 2009, 11:24:39 am
Is there something wrong?
No. This is due to the fact that the compiled one has still the debugging symbols included. You can either strip the symbols via the "-s" linker switch and/or run the update script that does that for you. However - debugging symbols won't harm in any way. So you surely can also just leave it like that.
Title: Re: Keyboard macros
Post by: vix on February 19, 2009, 03:32:36 pm
Yes, I understood that after a while...

Now I have another problem: the Record macro function doesn't work in my plugin
I can only Edit the macro and saving them...
Title: Re: Keyboard macros
Post by: jt421 on February 22, 2009, 04:51:37 pm
I would also like to try the keyboard macros plugin.  Is there somewhere I can get the source? (I am already building the nightly builds myself.)
Title: Re: Keyboard macros
Post by: vix on February 23, 2009, 01:31:03 pm
Quote
I would also like to try the keyboard macros plugin.  Is there somewhere I can get the source?
Some months ago they were available on savefile.com, but I think they have been removed...
Title: Re: Keyboard macros
Post by: Jenna on February 23, 2009, 02:08:49 pm
Quote
I would also like to try the keyboard macros plugin.  Is there somewhere I can get the source?
Some months ago they were available on savefile.com, but I think they have been removed...

If it's okay for the author (I think its pecan, right), you can send me the sources and I put it on my server.
Title: Re: Keyboard macros
Post by: Pecan on February 23, 2009, 03:04:32 pm
As soon as I get a chance, I'll re-instate the google project and upload the source.
Title: Re: Keyboard macros
Post by: Pecan on February 23, 2009, 03:41:43 pm
cbKeyMacs source version 0.3.17.0

Tested ok on svn 5218
http://code.google.com/p/cbkeymacs/downloads/list
Title: Re: Keyboard macros
Post by: vix on February 24, 2009, 08:45:55 am
Quote
cbKeyMacs source version 0.3.17.0
I rebuilt the dll, but I have the same problem.
Does the Record macro function work?
Title: Re: Keyboard macros
Post by: nanyu on February 24, 2009, 09:42:52 am
Quote
cbKeyMacs source version 0.3.17.0
I rebuilt the dll, but I have the same problem.
Does the Record macro function work?

I rebuild it also. and the pluging run ok.

but two lacking:

1. It can not work well with  c::b IDE which apply a  non-engilish local language. etc : Chinese.
   (reason: It can't find the "Tool" menuitem while was shown in Chinese char..)

2. It can not record the "Ctl + X /Ctl + V" key.
Title: Re: Keyboard macros
Post by: vix on February 24, 2009, 01:41:51 pm
Quote
I rebuild it also. and the pluging run ok.
What wxWidget version did you use? 2.8.6 or 2.8.9?

I select Record macro, then I execute the actions of the macro, at the end I select Stop recording...
and I expect to see a popup showing the macro, and asking how to save it, but nothing happens!!!
I'm not able to find the recorded macro anywhere
Title: Re: Keyboard macros
Post by: Pecan on February 24, 2009, 01:53:29 pm

1. It can not work well with  c::b IDE which apply a  non-engilish local language. etc : Chinese.
   (reason: It can't find the "Tool" menuitem while was shown in Chinese char..)

Macros that use the menu items must be corrected manually.
menu/plugins/KeyMacs/Edit macro

2. It can not record the "Ctl + X /Ctl + V" key.

Macros which use keys that are intercepted by the OS must be
corrected manually.
Menus/plugsin/KeyMacs/Edit macro
 
Title: Re: Keyboard macros
Post by: Pecan on February 24, 2009, 02:00:52 pm

I select Record macro, then I execute the actions of the macro, at the end I select Stop recording...
and I expect to see a popup showing the macro, and asking how to save it, but nothing happens!!!

I'm not able to find the recorded macro anywhere

Once played back, or stopped, the macro is automatically recorded in a macro named "Scratch".
Edit it with Menu/plugins/KeyMacs/Edit macros.
Scroll in the left table to find "Scratch". You can rename it so it's not over-written.
Title: Re: Keyboard macros
Post by: Pecan on February 24, 2009, 02:04:57 pm
KeyMacs plugin

KeyMacs (or Keyboard Macros) plugin enables Recording, Playback, and editing of keystroke macros.


Contents

    * 1 What is KeyMacs
    * 2 Recording and playback
    * 3 Named Key Symbols
    * 4 Special keys
    * 5 Quirks & restrictions.
    * 6 How do I install it?
    * 7 KeySym definitions
    * 8 Example KeyMacs

What is KeyMacs

KeyMacs is a Code::Blocks plugin providing the user an ability to group sequences of keystokes as a macro (KeyMac). The KeyMac can be executed by either the main Plugin menu, a menu command key, or the context menu.

The KeyMac "{END}{ENTER}//{TAB 2}", for example, will move the cursor to the end of the current line, start a new line, enter the C++ comment sequence and two tabs.

KeyMacs can be created in the KeyMac editor or by way of the "Record Macro" menu. The editor can be accessed via MainMenu => Plugins => KeyMacs => EditMacros.

(http://forums.codeblocks.org/index.php?action=dlattach;topic=9980.0;attach=3188;image)
Image:KeyMacs102.PNG

Within the editor, click the New button. A new empty "Untitled" macro is created. Click on "Untitled" and rename it, for example, MyMac. Hit enter to confirm the rename.

   {END}{ENTER}//{TAB 2}

Enter the above keymac into the right hand text window . Click within the "Menued Macro" check box to cause KeyMacs to add MyMac as an entry on the Pugins=>KeyMacs=>submenu and the CodeBlocks editor context menu.

(http://forums.codeblocks.org/index.php?action=dlattach;topic=9980.0;attach=3190;image)
Image:KeyMacs103.PNG

Within the Command Key edit box, enter the keystrokes "Ctrl-Alt-M". This is the command (hot) keys that will be placed on the menu entry for MyMac. This key sequence should be unique, not conficting with any other menu command key sequence used in the Code::Blocks menu system.

Click on OK to accept the KeyMac definition.

You will now see a MyMac menu entry at the bottom of the Menu=>Plugins=>KeyMacs menu panel with the command keys Ctrl-Alt-M.

Either clicking on the MyMac menu item, invoking it with the command keys, or choosing it from the KeyMacros context menu should produce "//" followed by two tabs as a new comment line in your edit window.

KeyMacs without command keys can still be "menued", and be invoked by clicking on them from either the main or context menu.

Recording and playback

KeyMac contain a "Record Macro" facility that stores each keystroke for later use by the "Play Macro" menu item.

Once recorded, stopped or played back, the keystrokes are stored in the KeyMacs Editor by the label "Scratch".

The Scratch macro is over written on each record, stop, or playback. If you wish to save it, you must use the KeyMacs editor to rename "Scratch" to some other label.

Recorded keymacs should be edited for accuracy. They may contain misinterpreted or unwanted keystrokes. A '{' brace recorded in a macro, for example, cannot be played back accurately as a character until it's surrounded by escape braces "{{}".

"!", "^", "+", cannot be played back as characters until they too are surrounded by braces; else they play back as the Alt, Ctrl, and Shift prefix modifiers for any key that follows them. Eg., "^c" is not the characters '^' and 'c', but the copy operation Ctrl-C. The character sequence must appear as "{^}c".

KeyMacs attempts to determine the intent of the user by surrounding single character occurances of these chars with escape braces, but it's not always correct.

If, during recording, the window focus leaves the editor, KeyMacs cannot see and record user key presses. They can, however, be re-entered into the macro via the KeyMacs editor.

Named Key Symbols

At the bottom of the KeyMacs editor is a list of key symbols (KeySyms) which represent functions performed for the user by KeyMacs. For example, {ENTER} emulates the user depressing then releasing the Enter key.

Other KeySyms, like {ALTDOWN}, depress the keys but do not release them until an opposite KeySym, like {ALTUP}, appears in the key macro stream. These "paired" KeySyms can cause havoc if not entered as matching pairs.

Eg., {CTRLDOWN}{RIGHT}{RIGHT}{CTRLUP} moves two words to the right.

KeySyms which cause movement may contain a numeric parameter. Eg, {RIGHT 4} will move the cursor 4 positions to the right.

   {WAIT 5} will pause for 5 milliseconds.
   {ASC 0191} will enter the char represented by ascii 191 into the editor.
   {ENTER 2} will create two new lines
   {UP}{DOWN}{RIGHT}{LEFT} are others.
   


Special keys

!, ^, +, represent the keystrokes Alt, Ctrl, and Shift respectively. They provide a modifier for the character key that follows it. When KeyMacs sees a "!c", it interprets it as an Alt-c; a "+v" as a Shift-v; a "^t" as a Ctrl-t. KeyMacs depresses the modifier key, depresses the char key, releases the char key, then releases the modifier key.

The brace set '{' and '}' are used to delineate special KeySyms. To use them as characters in a macro, they must be surrounded by braces themselves. IE., {{} and {}} correctly represent the left and right brace as characters.


Quirks & restrictions.

Key macros must begin execution from within an editor window. Once invoked from within an editor, macro keys may be injected into other windows, such as the find dialog. The sequence "^fPecan{ENTER}" would invoke the find dialog, insert the chars "Pecan" into the find text control, then execute the find by depressing and releasing the enter key.

Macros not checked as "Menued Macro" in the KeyMacs editor simply remain in the database for future reference. They can, of course, be deleted.

The macro database resides in the users home directory as cbKeyMacs.ini. The first section contains the macro definitions. The second section specifies the menu command keys or blank if "un-menued".

KeyMacs can execute other KeyMacs by referencing their menu command key. Be careful. This can cause an infinte loop if two macros invoke each other. To avoid this, a KeyMac that invokes another KeyMac should itself have no command keys.

A Keymac that is invoked by another KeyMac might execute asynchronously. Invoked KeyMacs do not return to the invoking Keymac The invoking KeyMac cannot wait for the invoked KeyMac. Most likely, the invoked KeyMac is queued up behind the invoking KeyMac, but it might also start its own thread.

The context {MENU} keysym opens on my Windows XP2 system at coordinates (0,0). I've found no way to change this annoying behavior.

KeyMacs injects keys into the focused window keyboard buffer. It attempts to start the KeyMac within the window that invoked the menu. But if you're running a "focus follows mouse" system, the mouse may change the window focus during KeyMac execution causing keys to input into the wrong window. Be careful of the mouse pointer location during invocations of the context menu.

On *nix. I have not yet succeeded in moving the mouse pointer back into the window owning the KeyMac when the mouse ends outside the owning window.

{ASC} is not available for *nix since XWindows does not support it.


How do I install it?

Download: http://code.google.com/p/cbkeymacs/downloads/list to a clean folder.

Compile KeyMacs for MSWindows with KeyMacs.cbp. Then copy KeyMacs.dll to ...\trunk\src\devel\share\CodeBlocks\plugins\KeyMacs.dll. Copy KeyMacs.zip to ...\trunk\src\devel\share\CodeBlocks\KeyMacs.zip

Compile KeyMacs for Linux with KeyMacs(unix).cbp. Then copy KeyMacs.dll to .../trunk/src/devel/share/codeclocks/plugins/KeyMacs.dll. Copy KeyMacs.zip to .../trunk/src/devel/share/codeblocks/KeyMacs.zip

Linux users will need the X11 and Xtst development libraries. These are usually already provided by the distribution. Ubuntu Synaptic provided the following libraries when I searched for xtst:

(http://forums.codeblocks.org/index.php?action=dlattach;topic=9980.0;attach=3192;image)
Image:KeyMacs107.PNG

KeySym definitions

   ^, !, + are key modifiers representing CTRL, ALT,SHIFT
   {ALT UP|DOWN} - Program menu invocation
   {BACKSPACE} or {BS}
   {DEL}
   {DELETE}
   {DOWN}
   {END}
   {ENTER}
   {ESC} or {ESCAPE}
   {F1} {F2} {F3} {F4} {F5} {F6} {F7} {F8} {F9} {F10} {F11} {F12}
   {HOME}
   {INS} or {INSERT}
   {LEFT} {RIGHT}
   {PGDN} {PGUP}
   {SPACE}
   {TAB}
   {UP}
   {PRINTSCREEN}
   {SCROLLLOCK}
   {NUMLOCK}
   {CTRLBREAK}
   {PAUSE}
   {CAPSLOCK}
   {NUMPAD0}
   {NUMPAD1} {NUMPAD2} {NUMPAD3} {NUMPAD4} {NUMPAD5} {NUMPAD6} {NUMPAD7}
   {NUMPAD8} {NUMPAD9} {NUMPADMULT} {NUMPADADD} {NUMPADSUB} {NUMPADDOT}
   {NUMPADDIV} {NUMPADENTER UP|DOWN}
   {MENU} - context menu
   {LCTRL} {RCTRL}
   {LALT} {RALT}
   {LSHIFT} {RSHIFT}
   {SLEEP}
   {CTRLDOWN} {CTRLUP}
   {ALTDOWN} {ALTUP}
   {SHIFTDOWN} {SHIFTUP}
   {ASC 0nnn}
   {WAIT}


Example KeyMacs

Use cmd key Ctrl-Enter to create a new indented line.

   "{END}{ENTER}"

Use Ctrl-P to enter the C++ pointer sequence (saving alot of mistypes)

   "->"

Use Alt-Ctrl-C to enter the C++ comment sequence

   "{END}{ENTER}//{TAB}"

Use Alt-Ctrl-B to enter a new set of formated braces

   "{END}{ENTER}{{}{ENTER 2}{HOME}{}}{UP}{TAB}"


Pecan 2007/01/15


[attachment deleted by admin]
Title: Re: Keyboard macros
Post by: vix on February 24, 2009, 02:24:16 pm
Quote
Quote
I'm not able to find the recorded macro anywhere
If, during recording, the window focus leaves the editor, KeyMacs cannot see and record user key presses.

That's was my problem... solved thanks
Title: Re: Keyboard macros
Post by: ollydbg on February 24, 2009, 03:00:41 pm
@Pecan
Great! Should be added to wiki page.
Title: Re: Keyboard macros
Post by: Andrej08 on July 04, 2010, 05:02:59 am
Well if anyone is interested, to build this plugin with CB 10.05 you need to add:

..\..\..\devel

to the Linker Search directories. And both the base and include fields for the cb global variable need to be set. (to \CB folder and \cb\src\include, respectively).

But tbh. the plugin is just way too slow for my liking. Even that simple example "{END}{ENTER}//{TAB 2} " takes almost 2 seconds to apply..
Title: Re: Keyboard macros
Post by: Cryogen on August 31, 2010, 02:30:25 am
 Hi Guys,

I've been meaning to do this for a while. I've updated KeyMacs to run on the latest SVN. It includes some configuration changes to allow compilation into standard directories, remove the $(cb) macro, etc. to align it with other contrib plug-ins and adds one include to NIXrunmacro.cpp so it compiles on Linux. I also made it insert into the Plugins menu in correct alphabetical order. I've bumped the version number in manifest.xml, just based on what's listed in version.h, as it was still showing 0.1.1.

I haven't changed the system makefile.am files to allow compilation with make under Linux but that is the work of 5 mins to change when it moves to contrib, as I think it should.

Tested in SVN 6557 on Win7 and Ubuntu Linux.

Enjoy.
Title: Re: Keyboard macros
Post by: codeur on February 05, 2011, 12:39:57 pm
Thanks Pecan, this plugin starts to address one major weakness of the editor.
The macro database resides in the users home directory as cbKeyMacs.ini
That's a pity. It should be saved instead to %AppData% like the data of other plugins. That would make it usable in portable CB.

Thanks Cryogen for the modified project. It builds well in contrib under Windows with trunk version 6956.
Title: Re: Keyboard macros
Post by: Pecan on February 05, 2011, 03:35:28 pm
The macro database resides in the users home directory as cbKeyMacs.ini
Quote
That's a pity. It should be saved instead to %AppData% like the data of other plugins. That would make it usable in portable CB.

Actually it does reside in AppData. My mistake.