Jump to content

Check MouseWheel Up or Down


beo6
 Share

Recommended Posts

Hello, i have a small problem to recognize if i moved the mousewheel up or down.

 

i get the mouse z value by:

local mouseWheelPos = window:GetMousePosition().z
System:Print("Mouse wheel: "..mouseWheelPos)

 

but i noticed that the value i get out of it always goes up. Only when a overflow happens the value swaps to a negative value.

 

The only difference is that the value goes up a lot more when scrolling down (35725856).

When scrolling up the value only goes up for a smaller amount (65536)

 

i could check for that amount but i am not convinced that this is constant for every mouse out there and it looks a bit odd to me.

 

 

Has anyone more knowledge?

Thanks

Link to comment
Share on other sites

ok. checking if the value changed about that amount is not reliable.

 

i also have sometimes the value change about 35725848 when scrolling down.

 

//Edit:

 

here is a function that seems to work for me.

Script.mouseWheel = 0
Script.wheelUp = 65536
Script.wheelDown = 35725848
function Script:GetMouseWheelDirection()
local context = Context:GetCurrent()
local window = context:GetWindow()
local wheelReturn = 0
local mouseWheelPos = window:GetMousePosition().z
if (self.mouseWheel ~= mouseWheelPos) then
 if ( mouseWheelPos > self.mouseWheel+self.wheelUp ) then
  wheelReturn = 1
  System:Print("Mouse wheel DOWN! ")
 elseif ( mouseWheelPos < self.mouseWheel+self.wheelDown ) then
  wheelReturn = 2
  System:Print("Mouse wheel UP! ")
 end
 self.mouseWheel = mouseWheelPos
end
return wheelReturn
end

 

It returns 0 when the wheel position didn't changed and 1 for Down or 2 for Up.

 

Maybe there is a better way. I will have to check if it works on other PCs etc.

Edited by beo6
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

 Share

×
×
  • Create New...