You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function func1(ch)
if (ch == " ") then
print("Doesn't work (this message is never shown).");
end
print("Typed a regular character like a, b, c, d, e, etc... works.")
end
npp.AddEventHandler("OnChar", func1)
If I assign it manually in Notepad++'s settings then it works but the default action of [tab] becomes disabled (so I can't make indentation then).
Is there a way to detect [tab] so that I could insert text after it's pressed with editor:AddText("text");?
At the lowest level (Scintilla) the SCK_TAB key is bound to the SCI_TAB command. I can't say for sure why it wouldn't trigger the "OnChar" event, but I would guess this is expected behavior from Scintilla. You'd probably have better luck using the "OnModification" event to see when a tab character is added, by that may not be as clean as you need.
At the Notepad++ level, "npp.AddShortcut" is used but it does not directly translate these shortcuts to Scintilla shortcuts (plus there are some limitations as to what can be assigned for some reason). If you assign a shortcut key to tab then yes it will override the Notepad++ behavior.
From the sound of it you are wanting Notepad++ to still do all of its work, and then add something extra. What I've had to do in some of my other plugins is hook the keyboard input with C code to let Notepad++ handle it like "normal" and then add some extra logic after it is done.
I've thought about adding that functionality to this plugin to be able to hook the keyboard input from Lua which would allow users to do something before, after, block, alter, etc keypresses. Would not be useful to alot of users but could still be useful if implemented correctly.
The other option would be to compile a C module to hook the keyboard that uses the Lua library distributed with this plugin. I know it is possible but haven't done it myself in a while.
Activity
dail8859 commentedon Apr 22, 2020
It depends exactly what you are needing to do.
At the lowest level (Scintilla) the
SCK_TABkey is bound to theSCI_TABcommand. I can't say for sure why it wouldn't trigger the"OnChar"event, but I would guess this is expected behavior from Scintilla. You'd probably have better luck using the"OnModification"event to see when a tab character is added, by that may not be as clean as you need.At the Notepad++ level,
"npp.AddShortcut"is used but it does not directly translate these shortcuts to Scintilla shortcuts (plus there are some limitations as to what can be assigned for some reason). If you assign a shortcut key to tab then yes it will override the Notepad++ behavior.From the sound of it you are wanting Notepad++ to still do all of its work, and then add something extra. What I've had to do in some of my other plugins is hook the keyboard input with C code to let Notepad++ handle it like "normal" and then add some extra logic after it is done.
dail8859 commentedon Apr 22, 2020
I've thought about adding that functionality to this plugin to be able to hook the keyboard input from Lua which would allow users to do something before, after, block, alter, etc keypresses. Would not be useful to alot of users but could still be useful if implemented correctly.
The other option would be to compile a C module to hook the keyboard that uses the Lua library distributed with this plugin. I know it is possible but haven't done it myself in a while.