Closed TetraTheta closed 1 year ago
Hi @TetraTheta
Notepad++ does some not-so-obvious things when starting up. In this case what is happening is the LuaScript plugin is running the script (and removing the shortcut keys successfully) before Notepad++ applies all of its settings, which is undoing all the changes from the script.
You can use the OnReady
callback to wait until Notepad++ is fully initialized.
The other thing to keep in mind is editor
is a reference to the currently active editor, but there are two concrete implementations editor1
and editor2
so you will want to make sure to apply the settings to both editors.
I tested this and got it to work.
function RemoveKeys(e)
e:ClearCmdKey(string.byte('E'), SCMOD_CTRL)
e:ClearCmdKey(string.byte('R'), SCMOD_CTRL)
e:ClearCmdKey(string.byte('E'), SCMOD_CTRL + SCMOD_SHIFT)
e:ClearCmdKey(string.byte('Y'), SCMOD_CTRL + SCMOD_SHIFT)
e:ClearCmdKey(string.byte('W'), SCMOD_CTRL + SCMOD_SHIFT)
e:ClearCmdKey(string.byte('O'), SCMOD_CTRL + SCMOD_SHIFT)
e:ClearCmdKey(string.byte('A'), SCMOD_CTRL + SCMOD_SHIFT)
e:ClearCmdKey(string.byte('D'), SCMOD_CTRL + SCMOD_SHIFT)
e:ClearCmdKey(string.byte('G'), SCMOD_CTRL + SCMOD_SHIFT)
e:ClearCmdKey(string.byte('H'), SCMOD_CTRL + SCMOD_SHIFT)
e:ClearCmdKey(string.byte('Z'), SCMOD_CTRL + SCMOD_SHIFT)
e:ClearCmdKey(string.byte('X'), SCMOD_CTRL + SCMOD_SHIFT)
e:ClearCmdKey(string.byte('C'), SCMOD_CTRL + SCMOD_SHIFT)
e:ClearCmdKey(string.byte('V'), SCMOD_CTRL + SCMOD_SHIFT)
e:ClearCmdKey(string.byte('B'), SCMOD_CTRL + SCMOD_SHIFT)
e:ClearCmdKey(string.byte('N'), SCMOD_CTRL + SCMOD_SHIFT)
e:ClearCmdKey(string.byte('6'), SCMOD_CTRL + SCMOD_SHIFT)
end
npp.AddEventHandler("OnReady", function()
RemoveKeys(editor1)
RemoveKeys(editor2)
print("Hello World")
return false
end)
``
Thanks, that solved the issue!
I'm trying to disable Scintilla keyboard shortcut which cannot be disabled by Notepad++ via LuaScript. I've saw a comment that LuaScript can do it.
Original comment was saying that this Lua code will work.
But after searching official documentation, I found that there is
Editor:ClearCmdKey
for clearing keyboard shortcut, which is exactly what I want.So I modified
startup.lua
script to be like this:I put
print("Hello World")
to test ifstartup.lua
is actually loaded or not. It loads up because I can see console output to be like this:But when I close all Notepad++ window and start new Notepad++ and press
Ctrl
+Shift
+D
, it putsEOT
character which LuaScript should prevent.I tested
editor:AssignCmdKey()
too, but it does nothing neither.Here are my debug information of Notepad++