Jump to content




Keybindings?


  • You cannot reply to this topic
2 replies to this topic

#1 ReBraLaCC

  • Members
  • 100 posts
  • LocationSublime Text 2

Posted 20 August 2016 - 10:01 AM

So i've been trying to get like ctrl+u and other keys to do things but the way i've tried it didn't work :(

while true do
 ev = {os.pullEvent()}
 if ev[1] == "key" then
   ev2 = {os.pullEvent()}
   if ev2[1] == "key" then
    if ev[2] == keys.leftCrtl and ev2[2] == keys.u then
     return true
    end
   end
 end
end

i hope that there is maybe a simpler way to do this and a working one :)

thanks
-- ReBraLa

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 20 August 2016 - 10:21 AM

View PostReBraLaCC, on 20 August 2016 - 10:01 AM, said:

if ev[2] == keys.leftCrtl and ev2[2] == keys.u then

Both can't be true at once.

You get one event per key pressed, in the order they're pressed. Under later versions of CC you also get "key_up" events indicating when keys are released. If you want to know whether multiple keys are held at the same time, then you'll need to record buttons of interest...

For eg:

local heldCtrl = false

while true do
	local ev = {os.pullEvent()}
	
	if ev[1] == "key" then
		if ev[2] == keys.leftCtrl then
			heldCtrl = true
		elseif heldCtrl and ev2[2] == keys.u then
			return true
		end
	elseif ev[1] == "key_up" and ev[2] == keys.leftCtrl then
		heldCtrl = false
	end
end


#3 ReBraLaCC

  • Members
  • 100 posts
  • LocationSublime Text 2

Posted 20 August 2016 - 10:43 AM

View PostBomb Bloke, on 20 August 2016 - 10:21 AM, said:

....

Thank you very much! You only had a lil typo but i fixed it :) going to leave this here... thats what i need it for :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users