It is possible to detect and override this behavior yourself.
When text is inserted by paste, you will get only the char events for the pasted characters, without the usual proceeding key events. A pull event replacement function can identify these cases for you.
--ctrlkey pullEvent replacement
--the previous event, held for checking
local prevEvent={}
--table mapping characters to the corresponding key ids
local charToKey = {["P"]=25,["S"]=31,["R"]=19,["U"]=22,["T"]=20,["W"]=17,["V"]=47,["Y"]=21,["X"]=45,["["]=26,["Z"]=44,["]"]=27,["\\"]=43,["_"]=12,["^"]=7,["a"]=30,["c"]=46,["b"]=48,["e"]=18,["d"]=32,["g"]=34,["f"]=33,["i"]=23,["h"]=35,["k"]=37,["j"]=36,["m"]=50,["l"]=38,["o"]=24,["n"]=49,["q"]=16,["p"]=25,["s"]=31,["r"]=19,["u"]=22,["t"]=20,["w"]=17,["v"]=47,["y"]=21,["x"]=45,["{"]=26,["z"]=44,["}"]=27,["|"]=43,["~"]=41,["!"]=2,["#"]=4,["\""]=40,["%"]=6,["$"]=5,["'"]=40,["&"]=8,[")"]=11,["("]=10,["+"]=13,["*"]=9,["-"]=12,[","]=51,["/"]=53,["."]=52,["1"]=2,["0"]=11,["3"]=4,["2"]=3,["5"]=6,["4"]=5,["7"]=8,["6"]=7,["9"]=10,["8"]=9,[";"]=39,[":"]=39,["="]=13,["<"]=51,["?"]=53,[">"]=52,["A"]=30,["@"]=3,["C"]=46,["B"]=48,["E"]=18,["D"]=32,["G"]=34,["F"]=33,["I"]=23,["H"]=35,["K"]=37,["J"]=36,["M"]=50,["L"]=38,["O"]=24,["N"]=49,["Q"]=16,}
function filteredPullEvent()
local e=nil
while e==nil do
e={os.pullEvent()}
if e[1]=="char" then
--event is char; was previous the corresponding key?
if prevEvent[2]~=charToKey[e[2]] then
--this char event had no key event; it is a pasted character.
--discard it, and the loop will repeat
e=nil
end
end
end
prevEvent=e
return unpack(e)
end
--test code to demonstrate
while true do
local event={filteredPullEvent()}
print(table.concat(event," "))
end
if you're already detecting ctrl+v, with ctrl held, rather than ctrl followed by v (which can be done in a vaguely similar way, see my ctrlkeys api in my apis thread for an example), then you should be able to figure out how to incorporate this into your existing function, or you can use it as-is here in this post.I just remembered after hitting submit, ctrl+v is an exception, in fact the ONLY ctrl+letter combination that can't be detected, because the v key event is eaten somewhere before it would be passed to lua. Ctrl+s, ctrl+r, ctrl-t, ctrl-c, and ctrl-x all pass key events for ctrl and the character, only ctrl+v does not, for some reason.
I think I've asked for this before, but if it is cc's code, and not something in java, that is eating this "v" event, I'd quite like to see that changed, so that ctrl+v behaves like all the other ctrl+letter key combinations.