ZeroBraneStudio
ZeroBraneStudio copied to clipboard
Add package event for EVT_CHAR
In fact I already use it in some of my plugins. This different from event key down so it allows to get real symbol (not keyboard key). So I think I can use it in my hotkey plugin to e.g. diffirintiate between upper and lower case This is my plugin
local Package = {
name = "onEditorKey event",
author = "Alexey Melnichuk",
version = '0.1.0',
description = [[
Maps wxEVT_CHAR event to onEditorKey pakage event
This event calls before editor write char.
And if plugin returns false then this char will be discarded.
]],
dependencies = "1.70",
}
local SET = setmetatable({}, {__mode = 'k'})
local function configure(editor)
if SET[editor] then return end
editor:Disconnect(wx.wxEVT_CHAR)
editor:Connect(wx.wxEVT_CHAR, function (event)
if PackageEventHandle("onEditorKey", editor, event) == false then
return
end
event:Skip()
end)
SET[editor] = true
end
return {
onEditorNew = function(_, editor) configure(editor) end,
onEditorLoad = function(_, editor) configure(editor) end,
}
I can definitely do this (so we can add onEditorChar), but does it do something that onEditorKeyDown doesn't? onEditorKeyDown can return false to "eat" the key as well...
From the doc
While both of these functions can be used with the events of wxEVT_KEY_DOWN, wxEVT_KEY_UP and wxEVT_CHAR types, the values returned by them are different for the first two events and the last one. For the latter, the key returned corresponds to the character that would appear in e.g. a text zone if the user pressed the key in it. As such, its value depends on the current state of the Shift key and, for the letters, on the state of Caps Lock modifier. For example, if A key is pressed without Shift being held down, wxKeyEvent of type wxEVT_CHAR generated for this key press will return (from either GetKeyCode() or GetUnicodeKey() as their meanings coincide for ASCII characters) key code of 97 corresponding the ASCII value of a
So, I use this event to handle braces and quotes. Also, right now i want to add support to my hotkeys module make single chars case sesetive