This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
LBPHacker's profile picture

Restrict hardcoded hotkeys to Left Control

Started by LBPHacker, 11 June 2013 - 08:19 AM
LBPHacker #1
Posted 11 June 2013 - 10:19 AM
Hardcoded hotkeys (not sure if that's the right term - they are hardcoded for me because I can't do anything to them)… By those, I mean Ctrl+S as Fast-Shutdown (or Panic-Shutdown, whatever), Ctrl+T as Terminate, and (which brought me here) Ctrl+V as Clipboard-Paste. Those are not coded into the Lua part of CC, right?

I've been writing my OS for a while, and I began to work on the GUI three days ago. I've just finished the textbox, and thought that implementing the cut-copy-paste trio wouldn't be so bad nor so hard. I use Right Control as the "System key", so the copy method will fire only if one presses RControl+C (I didn't want to use LControl because of the old programs like "edit"). RControl+C works fine, okay. But when I tried to handle RControl+V, a lot of char events popped up from nowhere. I realized then, that's the hardcoded Clipboard-Paste function - it was pasting the contents of my clipboard.

So that. I'd like to suggest restricting these hardcoded hotkeys to LControl only, because:
  • This would allow people better handling of hotkeys.
  • As far as I know, there is no key on the right side of the keyboard that fires one of these hardcoded functions anyways.
  • Not to mention that I would be able to continue developing my OS :D/>
That's it.

LBPHacker
MudkipTheEpic #2
Posted 11 June 2013 - 10:46 AM
I think this would be great. I never use right control for that stuff anyway.
JJRcop #3
Posted 11 June 2013 - 06:42 PM
This would be great.
Sammich Lord #4
Posted 11 June 2013 - 07:36 PM
  • Not to mention that I would be able to continue developing my OS :D/>
When suggesting something you should think about what it does for the mod, not what it does for you.
MudkipTheEpic #5
Posted 11 June 2013 - 08:33 PM
Hardcoded hotkeys (not sure if that's the right term - they are hardcoded for me because I can't do anything to them)… By those, I mean Ctrl+S as Fast-Shutdown (or Panic-Shutdown, whatever), Ctrl+T as Terminate, and (which brought me here) Ctrl+V as Clipboard-Paste. Those are not coded into the Lua part of CC, right?

I've been writing my OS for a while, and I began to work on the GUI three days ago. I've just finished the textbox, and thought that implementing the cut-copy-paste trio wouldn't be so bad nor so hard. I use Right Control as the "System key", so the copy method will fire only if one presses RControl+C (I didn't want to use LControl because of the old programs like "edit"). RControl+C works fine, okay. But when I tried to handle RControl+V, a lot of char events popped up from nowhere. I realized then, that's the hardcoded Clipboard-Paste function - it was pasting the contents of my clipboard.

So that. I'd like to suggest restricting these hardcoded hotkeys to LControl only, because:
  • This would allow people better handling of hotkeys.
  • As far as I know, there is no key on the right side of the keyboard that fires one of these hardcoded functions anyways.
  • Not to mention that I would be able to continue developing my OS :D/>
That's it.

LBPHacker


  • Not to mention that I would be able to continue developing my OS :D/>
When suggesting something you should think about what it does for the mod, not what it does for you.

He didn't JUST suggest that, you know. And I can see a bunch of uses for this making THE MOD better too.
Sammich Lord #6
Posted 11 June 2013 - 08:45 PM
  • Not to mention that I would be able to continue developing my OS :D/>
When suggesting something you should think about what it does for the mod, not what it does for you.

He didn't JUST suggest that, you know. And I can see a bunch of uses for this making THE MOD better too.
I know he suggested more than just that. But the point of a suggestion is to convince the authors why a suggestion will help the mod out. If they accepted every suggestion to help one person out the mod will be total crap.
JJRcop #7
Posted 11 June 2013 - 09:32 PM
-snip-
When suggesting something you should think about what it does for the mod, not what it does for you.

He didn't JUST suggest that, you know. And I can see a bunch of uses for this making THE MOD better too.
I know he suggested more than just that. But the point of a suggestion is to convince the authors why a suggestion will help the mod out. If they accepted every suggestion to help one person out the mod will be total crap.
It helps a lot of people out, and allows them to use those hotkeys for the right-control without worry of triggering the system hotkeys.
Sammich Lord #8
Posted 11 June 2013 - 10:26 PM
-snip-
When suggesting something you should think about what it does for the mod, not what it does for you.

He didn't JUST suggest that, you know. And I can see a bunch of uses for this making THE MOD better too.
I know he suggested more than just that. But the point of a suggestion is to convince the authors why a suggestion will help the mod out. If they accepted every suggestion to help one person out the mod will be total crap.
It helps a lot of people out, and allows them to use those hotkeys for the right-control without worry of triggering the system hotkeys.
He makes good points with this suggestion, I never said he didn't. I was just stating in general you shouldn't make a suggestion for yourself, but instead make it for the mod itself.
superaxander #9
Posted 12 June 2013 - 02:19 AM
This indeed would be quite nice
GopherAtl #10
Posted 12 June 2013 - 02:47 PM
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,["&amp;"]=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.
Engineer #11
Posted 18 June 2013 - 02:00 PM
I think this really should be implemented for possibilities that are awesome! :D/>
aaa #12
Posted 04 July 2013 - 01:32 PM
-snip-
When suggesting something you should think about what it does for the mod, not what it does for you.
He didn't JUST suggest that, you know. And I can see a bunch of uses for this making THE MOD better too.
I know he suggested more than just that. But the point of a suggestion is to convince the authors why a suggestion will help the mod out. If they accepted every suggestion to help one person out the mod will be total crap.
It helps a lot of people out, and allows them to use those hotkeys for the right-control without worry of triggering the system hotkeys.
He makes good points with this suggestion, I never said he didn't. I was just stating in general you shouldn't make a suggestion for yourself, but instead make it for the mod itself.

Some people are coding their own OS, or looking for OS coded by someone else, or at least for IDE ; and that's a problem he encounters doing this. Making suggestions based on personal experience makes more sense than trying to imagine what would possibly fit to the mod. That's precisely the point and the use of suggestions.
robhol #13
Posted 05 July 2013 - 04:12 AM
I know he suggested more than just that. But the point of a suggestion is to convince the authors why a suggestion will help the mod out. If they accepted every suggestion to help one person out the mod will be total crap.

Lol. Because there's a real danger of that happening(!)
ChunLing #14
Posted 05 July 2013 - 05:40 PM
Okay, the real danger would be that they simply started ignoring user feedback entirely. Which I sometimes think wouldn't be a terrible thing anyway.