Page 1 of 1

Keystroke recorder with TextEditor

Posted: Monday 27th March 2023 10:54am
by BruceSteers
I've been working on something for my script editor.

It's a keystroke recorder for TextEditor.

How it works....

When active (recording) as keys are pressed the Key data is converted to a MacroKey object then added to a list of MacroKeys.

When played back the MacroKeys are sent to the Texteditor via a complete copy of the View_KeyPress() event. _MacroKeyPress()

The _MacroKeyPress method uses MacroKey instead of Key and the events are processed as normal key presses.

you can save.load macros too

Attached is a test application that lets you load files (or press dbg to insert the Key constants for testing)

This is still in infancy and will need some bug testing.

But it currently has been tested working on Mint-MATE with gtk3 and qt5

To use it in your own editor project just copy the KeyMacros and gb.form.editor folders from this project to yours.
(this contains it's own gb.form.editor component so do not add the gambas one to your project properties)
add gb.eval and gv.eval.highlight though.

See FMain.class to see how i have used it.

Usefull tips.
F3 will search-next if you have pressed Ctrl+F to open the Find-tool and searched text. (Shift+F3 to search backwards)

How macros can be very useful..
With combinations of using Ctrl Shift and arrow keys you can select words, copy/paste, etc move words around.
It can be very useful if you have a whole lot of lines of code that need adjusting but not in a way that find-replace helps.

So if you have 50 lines that need adjustment you can .....
Put the cursor at the start of the first line,
Enable the recorder.
Press keys to edit the line (being mindful of the fact you are recording strokes for playback)
Then usually finish by pressing Home key then Down key to be at the start of the next line.
Then stop the recorder.

Then just hit Play 49 times (or hold finger on F7)
zoooom 49 lines of code adapted in a flash :)

See me make a Collection out of a list of key codes in only a few moments in the clip.


Re: Keystroke recorder with TextEditor

Posted: Monday 27th March 2023 4:03pm
by cogier
I can't get the video to work in your post, but it works here.

Re: Keystroke recorder with TextEditor

Posted: Monday 27th March 2023 4:58pm
by BruceSteers
cogier wrote: Monday 27th March 2023 4:03pm I can't get the video to work in your post, but it works here.
yeah wierd , i see it fine on my computer but not on my phone
I changed the link to be the dns name not the static ip,


might be because my server is http not https

Re: Keystroke recorder with TextEditor

Posted: Sunday 30th April 2023 9:56pm
by BruceSteers
And now my gambas IDE has a keystroke recorder :)
https://gitlab.com/bsteers4/gambas/-/co ... 49e7692ee9

:D

Re: Keystroke recorder with TextEditor

Posted: Thursday 11th May 2023 12:43pm
by BruceSteers
Benoit has spoken about looking into possibly being able to fake Key class.

That could open up all sorts of possibilities. It would essentially give us an X11.SendKey() like method that would work on ALL systems and all controls.

It would certainly make a Keystroke recorder easier to code as we could use the original KeyPress method not my copy of it.,
imagine being able to fake Key class then trigger KeyPress events, :)


I have made some changes to this test app.

My discoveries...

Custom Menu shortcuts get hidden from TextEditor_KeyPress
For example if you have configured your own F3 and Shift+F3 shortcuts to search next/previous text, if you press the keys the TextEditor does not register the press.
The Workaround: I added a way to manually add a macrokey with an AddKey(MacroKey) and AddShortCut(sText) function.
So now in the mnuFindNext_Click() event i use hEditor._Macro.AddShortCut("F3")

This has to be done for anything that has it's own shortcut set by the programmer but not for any TextEditor built in shortcuts.
For example if you do not set your own F3 shortcut to manage FindNext the editor does it by default. in that case code is not needed and it should work as expected. same for Ctrl+C Ctrl+V etc