I currently don't have a many mouse button mouse at home, but i found nothing about this online.
Will Input.GetMouseButton(x) will read my mouse Xth button for example.
Will this return true if i hold down my mouse 4th mouse button?
bool holding = Input.GetMouseButton(4);
The unity doc only mentions mouse button 1,2 and 3 :/
Actually, yes the function Input.GetMouseButton(4) will read in the 4th mouse button on your mouse when held down :)
(I tested this like half a year ago, Unity doc team should have mentioned this indeed that it can read any mouse buttons, so we dont need to test it :P)
Related
I am currently developing a UI for my Unity game. Due that I have started creating a KeyBinder-Menu where one can reassign the keys. This works fine until I tryed to implement it for the Mousebuttons.
I tried using Event.current.button so i can handle mouse input, but first of all it returns 0 all the time when i am not pressing anything else then mousebutton 0 and secondly it does not react to my extra mousebuttons.
Then I tryed Input.GetKeyDown(KeyCode.MouseX) (X would be the mousebutton I want to handle) This works fine with mousebutton 0, 1 and 2 but does not work with my extrabuttons to. I have a Mouse from Logitech with 2 extra buttons and they work fine with all games (like lol, Rainbow, minecraft ....) so I dont know why unity can not handle them.
Thanks for all answers I may get.
This is currently a bug, i already submitted a bug report about it you can vote for it here:
https://issuetracker.unity3d.com/issues/event-dot-button-only-supports-right-left-and-middle-mouse-buttons
However Input.GetMouseButton(x); will still read your extra mouse buttons correctly where x is an integer
Eg.: Input.GetMouseButton(12); will read your 12th mouse button on a gaming mouse ...
You can also do release, push events:
Returns true during the frame the user pressed the given mouse button.
Input.GetMouseButtonDown(int button);
Returns whether the given mouse button is held down or not.
Input.GetMouseButton(int button);
Returns true during the frame the user releases the given mouse button.
Input.GetMouseButtonUp(int button);
Update from Unity:
Thanks again for reporting this issue. It has been reviewed by our developers and unfortunately, it has been decided that it will not be fixed. As of now, IMGUI doesn't support more than 3 buttons, and since IMGUI is being replaced with UIElements this ability is not going to be added.
Hy guys! I am in trouble checking if the mouse has clicked on a specific "button".
I check (MouseState.Leftbutton) first to be "Pressed" then i check the area i want to.
it works well when i click on the "button", but if i click somewhere near the button, and i drag the mouse on the button keeping the button pressed, it acts if i would pressed the button because (mouseState.Leftbutton = Pressed) and the mouse is in the area, both occurs at once.
How can i check mouse coordinates at the moment of pressing down the left mouse button?
Sorry for bad english :D
I strongy advise you against "Pressed"(or Click) event. Use MouseDown and MouseUp events instead. If you try to use any button in "official" applications - you can see it is mostly MouseUp event (or less common MouseDown)
Mouse.GetState().X
Mouse.GetState().Y
These are the co-ordinates of your mouse position. If you are trying to do a click on a button ,follow this method.
let your button coordinates be buttonPostion.X and buttonPosition.Y on the screen.
then,
MouseState mouseClick = Mouse.GetState();
if (Mouse.GetState().X == buttonPosition.X && Mouse.GetState().Y == buttonPosition.Y)
{
if (mouseClick.LeftButton == ButtonState.Pressed)
{
//Your process when the button is pressed
}
}
I hope I answered your question more or less.
In Excel, middle mouse button click work as a toggle. That is, if you press it once, it will allow you to scroll in your chosen direction till the time you click it again.
However, in Infragistics Ultragrid, this scrolling functionality is available only while middle mouse button remains pressed. How can I make Infragistics Ultragrid middle mouse button click work as in excel?
Otherwise also, what is the way to do it in winforms?
It's not as complicated as you might think. Clicking either the mouse wheel or middle button (depending on the type of Mouse the user has) fires off a MouseWheel event which must be handled and processed like any other event.
You'll need to configure a small "scrolling state machine" for you application. By this, I mean that the user is either scrolling in, say, a NormalMode, where using scroll bars or flicking up/down on the mouse wheel produces the same effect (scrolling up/down). Or, the application is in a HoverScrollingMode which occurs whenever the user has clicked the middle button (or mouse wheel) and is moving the mouse north or south of the click point.
I can't give you a programming example without seeing how your application currently handles other types of mouse events, but your overall strategy is to handle these MouseWheel events, use them to switch your application state (into, say, HoverScrollingMode) and then programmatically move the viewport up/down depending on the current position of their mouse.
Hope this helps, and good luck!
This is probably a n00b query. I have a need where I want to change the trackbar value based on a mouse down event. This I achieved as follows:
private void MoveTrackBarToMouseClickLocation(TrackBar a_tBar, int a_mouseX)
{
// Jump to the clicked location
double dblValue;
dblValue = ((double)a_mouseX / (double)a_tBar.Width) * (a_tBar.Maximum - a_tBar.Minimum);
a_tBar.Value = Convert.ToInt32(dblValue);
}
That part works fine. I am having trouble getting the scroll working while the mouse button is pressed. e.g. If I click on the trackbar and it takes me to say value 50 with the mouse down, I want to be able to scroll right or left (from value=50) while that mouse is down.
I hope I have made my small issue clear.
Any help is appreciated.
Thanks
You need to execute your code in the MouseMove event, as well as the MouseDown event.
This event occurs when the mouse is moved while one of the buttons is held down. In contrast, the MouseDown event that you currently handle only gets raised once each time the mouse button is pressed down. That's why the TrackBar is not moving when the user moves the mouse, but is working properly the first time the button is pressed.
You didn't show the code where you wired up the event handlers and/or call the MoveTrackBarToMouseClickLocation function, so that's as specific as I can get. But if you managed to wire up the MouseDown event already, this should be a simple fix.
I'd like to do Drag & Drop with the right mouse button instead with the left one. However calling
DragDrop.DoDragDrop()
from MouseRightButtonDown instead of MouseLeftButtonDown doesn't do the job - DragDrop.DoDragDrop looks for mouse movements while holding down the left mouse button. Any idea how to realise Drag & Drop using the right mouse button? Thanks for any hint!
You need to make use of DragDrop.AddQueryContinueDragHandler(). Please see this post for details.