Jump to content

[1.8] [Resolved] perform event on MouseClick only when Control key down


DJD

Recommended Posts

What is the way to handle doing something on a  MouseClick but only if a control key is pressed at the time ?

 

I can register a keybinding and get that to work, and I can get a click event to work, but since they are separate events, how do you combine them into one ?

I don't keep an open mind lest someone try to fill it with garbage - Mark Twain

Link to comment
Share on other sites

Thanks !

 

I was looking at tutorials and they all had parts of what I needed but then again it seems things changed in 1.7 so I was a bit confused and some of the tutorials are for an earlier version....

I don't keep an open mind lest someone try to fill it with garbage - Mark Twain

Link to comment
Share on other sites

The reason you would use KeyInputEvent is if you want the actual key press to trigger something directly, e.g. press 'x' to open a GUI.

 

If your key binding is used elsewhere, such as in combination with a mouse click, then as diesieben said, you don't need KeyInputEvent for that particular case.

 

Furthermore, if you don't care about users being able to change the key used, you can get away without a KeyBinding at all and just use the Keyboard object directly to check key states. This is what happens in GUIs (indirectly), for example, when the Escape key is pressed.

Link to comment
Share on other sites

The reason you would use KeyInputEvent is if you want the actual key press to trigger something directly, e.g. press 'x' to open a GUI.

Nope, no need to.

In that case you would use ClientTickEvent (which actually fires more rarely than KeyInputEvent most of the time) and check for your key being pressed there.

My understanding is that KeyInputEvent fires immediately when a key is pressed, whereas ClientTickEvent you'd not only be waiting to process the input (granted probably an imperceptible amount of time), but you'd be taking a craps shoot as the key might not still be pressed if the player simply tapped it very quickly (very unlikely, but still), depending on whether you check if the key is still down or if the pressed variable was incremented and has yet to be decremented.

 

Plus, semantically, it makes more sense to use the KeyInputEvent, though subscribing to it may waste some resources by processing for every single key when one only actually cares about a few.

 

Am I completely off base here, i.e. is that not how it works? If your situation is very dependent on the timely processing of the key press, e.g. combat / movement related, wouldn't you want KeyInputEvent?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.