- Home /
Different action if a key is pressed when the mouse is clicked
I'd like to handle combinations of mouse and keyboard events. For example, if I click on an object while I'm pressing the CTRL key button, the action will be different compared to a simple click with no key buttons pressed. Is that possible? If yes, how?
Thank you
Answer by NoseKills · May 07, 2015 at 08:27 PM
void Update()
{
if (Input.GetKey(KeyCode.LeftControl))
{
if (Input.GetMouseButtonDown(0))
{
Debug.Log("This is a control-click");
}
}
}
Answer by TLummen · Jun 13, 2021 at 01:51 PM
if (Input.GetKey(KeyCode.Z) && Input.GetMouseButtonDown(0)) { // Do something here }
detects if the z key is held down while you click the mouse
Your answer
Follow this Question
Related Questions
How do i change controller from keyboard to mouse?? 1 Answer
Unity UI Mouse + Keyboard navigate, Un-Highlight button choice on mouse over 0 Answers
How to avoid multiple mouse clicks registering in OnGUI? 1 Answer
Best Practice Multiple Control Methods 1 Answer
my character settings are set for joystick how do i make em work with keyboard 0 Answers