apply last-event with any-key not working as expected - progress-4gl

I have an editor which is linked to a database field.
When the user pushes certain keys the program should behave differently,
for the rest of keys it should maintain the default behaviour. I am using this part of code:
ON ANY-KEY OF editor_1 IN FRAME F-Main
DO:
APPLY LAST-EVENT:LABEL TO SELF.
RETURN NO-APPLY.
END.
The problem is that when APPLY LAST-EVENT:LABEL is executed the editor does not behave as default.
Some examples of the behaviour by default, i.e. when any-key is not triggered:
CTRL+C is used for copying selected text
CTRL+V is used for pasting the copyed text
After triggering any-key in the editor, the program works like this:
CTRL+C aplication ABORTS
CTRL+V does not work
CURSORS DOWN/RIGHT/LEFT/UP do not work
BACKSPACE does not work
Is there anyway of triggering any-key without overwritting the default behaviour?
Note: Progress 4GL is v11.3 and is executed from windows.

You should map the key labels to the key FUNCTION that you want to apply.
Something like:
ON ANY-KEY OF editor_1 IN FRAME F-Main
DO:
if last-event:label = "backspace" then
apply delete-char to self.
else
apply lastkey to self.
/* use a CASE statement to extend this... */
RETURN NO-APPLY.
END.

I talked to progress and there is no solution for this issue. This issue with ANY-KEY is related to editors.
You could map some key labels to specific key FUNCTION, but there are certain events where it is not possible (for example, cursor movements).
At the end I had to trigger for special keys, but in this particular case it was preferable something like ANY-KEY.

Instead of triggering an event on any key, why not just do it for those special keys?
For example, the control-C behavior would be in this trigger:
ON CTRL-C of editor_1 IN FRAME F-Main

Related

How to remap Tab key to two dots/period key presses

I want to map two dot/period key presses to Tab key in AutoHotkey script. I tried to map similarly as its shown for remapping semicolon key - on AutoHotkey forums, but it doesn't work. I tried following:
1. `..`::Tab
2. ..::Tab
AutoHotkey gives an error
.
I tried searching on AutoHotkey Remap docs, but couldn't figure it out. The period key is the one with the greater than mark and not the number keypad period key. See this: Dot/period key
Addition info/context in response to reply by user 0x464e:
Basically, I am trying to expand Emmet style abbreviations in devtools style sub-panel since the chrome devtools team wont implement it.
I am not a fast typist, so it's a pain to type complete property names. For example, if I want to type margin-top, (see the image), Chrome autocomplete brings up margin, margin-block margin-block-end etc.
Now, for margin-top, you need to at least type margin-t to get the autocomplete to show that property.
This is the case for many very common CSS properties like margins, paddings, etc., so autocomplete isn't great.
On the other hand, if I just type mt and have Autohotkey expand to margin-top, it's much much faster, saves me much time and keeps me sane.
Basically, I have setup some hotstring in .ahk script and they work too.
However, if I press mt followed by a Tab key press, Chrome's autocomplete takes over and hotstring fails, (try once to see the problem). Instead, currently I press spacebar, or . (period) to trigger the hotstring. It works, but the problem is it leaves a space or a dot with the expanded text. [see this].
So, that's the actual reason I wanted a double period key trigger to replace Tab.
It would be great if the hotstring trigger would work with a double period key, but doesn't leave the trigger character itself and then have send Tab so as to jump to the value input of the just expanded property.
You're not really looking for a traditional remap, which is why you didn't find it from the documentation.
Remapping is just simply remapping one key to another, but you're not trying to do that. You're trying to make some action do another action.
Anyway, what you're asking is doable, but there's loads of different ways it can be achieved with difficulties varying from simple to extremely advanced & complicated.
You'll need to specify things more clearly before this can be answered properly.
Biggest questions that pop into my head right away are at least:
Should this work everywhere, or just in text input fields?
How should the original functionality of . be preserved, if at all.
(What should happen after the initial . keypress?)
Should there be some timeout between the keypresses?
Etc, this is just what I could think of right away, but surely there's more.
Anyway, for now I can give a simple implementation with a hotstring:
:*?:..::{Tab}
So this is a hotstring with the * and ? options.
I'm guessing these would probably be pretty good options for this.
So what this does, is it presses backspace twice and sends a Tab if you type ...
This should be fine for text editors, but it leaves much to be desired (the points I listed above aren't considered since I can't know what you're looking for. This is just what a default simple hotstring can offer).
Looks to me like you don't actually want the additional mapping of .. to Tab, but instead just want to update your existing hotstrings to activate immediately (without waiting for an EndChar) when the hotstring is followed by ..
Normally, you might look to the Ending Characters option to create this functionality, but since you want multiple characters to trigger this, we need to look to other options.
I will be using the example of ::mt::margin-top for my sample implementation. Extend any changes I make to these to the rest of your hotstrings in the script you screenshotted.
Here are the changes I am making to this example:
Add your .. to the end of each of your hotstrings triggers. For example ::mt::margin-top becomes ::mt..::margin-top. However, at this present, this still requires some sort of ending character to be pressed in order to proc. Let's fix that in the next step
Add the Asterisk Modifier to the hotstring. From the docs:
* (asterisk): An ending character (e.g. Space, ., or Enter) is not required to trigger the hotstring.
Final code for ::mt::margin-top example:
:*:mt..::margin-top
And extend this * insertion and .. appendation to each of your hotstrings.
Hope this helped! Lmk if you need any more help or changes.

How to move cursor to a C++ function(method)'s name from its body in VSCode with VIM extension

I'm developing some C++ code with VSCode+VIM extension. From time to time I need to do this while reading code: say I'm inside a long function and I want to know who called it. The first step to do is to move cursor directly under function's name so that I can invoke some keystrokes to show references.
What I'm current using is to press "[" key twice which will bring me to the opening bracket of the function. Since I have to follow some coding standard, the typical scenario is like this:
ReturnType ClassName::FunctionName(
ParamType1 param1,
ParamType2 param2,
ParamType3 param3)
{ // <-- Cursor here
......
}
Then I need to press "k" several times to move cursor under "ReturnType", depending on how many parameters are there. Next, I still have to press "w" 3 times to eventually move cursor from "ReturnType", to "FunctionName".
As you can see, this is a little painful here. I've tried easy motion approach with VSCode VIM extension, this makes my life a little easier, but I'm looking for a even better one.
Any VIM trick or VSCode extension can do this decently?
Any help will be appreciated, thanks!
To avoid having to press k a variable number of times it's possible to make use of the fact that the ) is right on the line above, and use % to go to the matching (. The complete key sequence is [[b%b.
However the first b will go to the ( if there's nothing between the parentheses. [[ge%b can be used instead.
If there's something between ) and { (such as a const qualifier) [[?)<cr>%b would work (this solution is complex and perhaps only useful in a key binding?)
[[?(<cr>b works too as long as there's no parameter that contains an open parentheses (such as in FunctionName(int (*function_pointer)(int, int)) { ... })

Conditional Key Remapping AHK

I would like to remap the 'j' key so that it presses n when ergo is true, or y when it is false with AutoHotKey. When I remap normally using "j::n" for example, shift+j outputs a capital N, and so do other modifiers with the 'j' key. However, my code below only works when the letters are pressed without modifiers. Is there a way to get around this, and conditionally remap keys with AutoHotKey?
j::
if (ergo) ;inverted use of the ergo variable to make the code more efficient
Send {n}
else
Send {y}
return
You only want to wrap characters which have a special meaning in a send command in { }. Basically escaping, if you're familiar with that what is.
So you don't want to wrap n or y in { }. It can even result in undesired behavior.
There are quite a few approaches for this. Can't say which is best, since don't know what your full script is like.
I'll present two options that I'd guess to be most likely best approaches for you.
Firstly, the send command way like you tried. Just doing it right:
*j::
if (ergo)
SendInput, {Blind}n
else
SendInput, {Blind}y
return
So, usage of the *(docs) modifier so the hotkey works even if extra modifiers are being held down.
And then usage of the blind send mode so which ever modifier keys you may be holding when triggering the hotkey will not be released.
Also switched over to SendInput due to it being the recommended faster and more reliable send mode.
Second way would be creating a context sensitive hotkey with #If(docs).
#If, ergo
j::n
#If
j::y
This is a convenient and easy approach. But could possibly result in other problems.
Why? Well #If comes with some downsides which you can read more about here, but long story short:
You likely wont have any trouble unless you have a more complicated script.
When I remap normally using "j::n" for example, shift+j outputs a capital N, and so do other modifiers with the 'j' key. However, my code below only works when the letters are pressed without modifiers.
Looks like you are looking for the Wildcard * modifier.
From the docs:
Wildcard: Fire the hotkey even if extra modifiers are being held down. This is often used in conjunction with remapping keys or buttons.
So after this change, your code would look something like:
*j::
if (ergo) ;inverted use of the ergo variable to make the code more efficient
Send {n}
else
Send {y}
return

AutoHotKey function to perform File-Rename without relying on sending F2 key code

I want define a custom hotkey to rename a selected file in File Explorer. So my new hotkey should behave exactly like the F2 key does by default. That is, when I press the hotkeys, the file name should be editable, allowing me to type a new name. However, I can't use the F2 key to cause windows to do this.
The reason is that I'm using the default hotkeys for something else. I am often running an application (unrelated to AutoHotKey) where the buttons in the UI are triggered using keyhooking for all of the F keys. The only suggestions that I can find on this are to have my custom hotkey use 'send' to raise the default key codes that would be associated with the action. This won't work, because I am using those hotkeys for something else. What I need is a solution that causes a file to be renameable without sending the F2 keycode.
^+!R::
Send {F2} ;This won't work for me
return
Actually the original hotkey can be used, just add $ before the hotkey that you don't want to be fired by the send command. Also using app-specific hotkeys a good idea to minimize possible conflicts.
Try this:
#If winActive("ahk_exe Explorer.EXE")
^+!R::
send {F2}
return
$F2::
send {down}
return
In case you have an application which scans the F2 key globally and unconditionally, and you cannot redefine it, there is not much you can do from within AHK. So ideally you should get rid of that application, and use e.g. AHK for same functionality, or find some workaround.
In this particular case the easiest workaround is alternative way to rename the file:
^+!R::
send {AppsKey}
sleep 100
send {m}
return

Why does Emacs sometimes overwrite characters when I insert or delete?

This happens for me all the time. Upon insertion/deletion, the positions of other characters in the buffer are not shifted.
For example, with buffer contents this is important content, inserting very before important results in the two words very and important appearing overlapped, like this: this is veryrtant content instead of this is very important content
How can I fix this?
Killing the buffer and reopening of course works.
It sounds like you have accidentally turned on overwrite-mode.
That command is a toggle. It is bound by default to the keys <insertchar> and <insert>. Typically one of those keys in a keyboard key labeled Insert.
But perhaps your keyboard is sending that key when you do something else.
Does the overwriting ever turn off? If so, that would suggest that you accidentally hit the toggle key a second time.
If not, then perhaps your keyboard or terminal is itself somehow locked in an overwriting mode. Do you see the same behavior outside of Emacs?