Keystroke recorder with TextEditor

Post your must have Gambas Components/Controls/Classes/Modules here.
Post Reply
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Keystroke recorder with TextEditor

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

Attachments
MacroRecorder-0.0.3.tar.gz
(64.55 KiB) Downloaded 191 times
If at first you don't succeed , try doing something differently.
BruceS
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Keystroke recorder with TextEditor

Post by cogier »

I can't get the video to work in your post, but it works here.
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Keystroke recorder with TextEditor

Post 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
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Keystroke recorder with TextEditor

Post by BruceSteers »

And now my gambas IDE has a keystroke recorder :)
https://gitlab.com/bsteers4/gambas/-/co ... 49e7692ee9

:D
Attachments
Untitled.jpg
Untitled.jpg (120.33 KiB) Viewed 4600 times
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Keystroke recorder with TextEditor

Post 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
Attachments
MacroRecorder-1.0.1.tar.gz
(66.91 KiB) Downloaded 181 times
If at first you don't succeed , try doing something differently.
BruceS
Post Reply