PDA

View Full Version : mouseUp event



Traveler
13-10-2007, 10:07 PM
I have a bit of a problem where I'm trying to get certain events to fire when the mouse buttons are released.
I'm searching the solution in states, like for example
if (Input.mouse.Buttons[mbLeft]) and (isUp in Input.mouse.states) then <dosomething>
but that does not appear to work, as nothting seems to be happening.

It's probably something simple, but I dont see it.
So, any hints or tips would be appreciated :)

pstudio
13-10-2007, 10:26 PM
I believe you would have to make MouseUpHandler like this

TPHXInputListener.getInstance.addMouseUpHandler(mo useuppro)
Where mouseuppro is a class procedure.

There's an example of making a KeyPressHandler in the Input Demo that should make a good reference ;)

Andreaz
14-10-2007, 08:18 AM
I have a bit of a problem where I'm trying to get certain events to fire when the mouse buttons are released.
I'm searching the solution in states, like for example
if (Input.mouse.Buttons[mbLeft]) and (isUp in Input.mouse.states) then <dosomething>
but that does not appear to work, as nothting seems to be happening.

It's probably something simple, but I dont see it.
So, any hints or tips would be appreciated :)

Easiest is to do as pstudio said.

if (Input.mouse.Buttons[mbLeft]) and (isUp in Input.mouse.states) then <dosomething>

This code snippet just says if the Left mouse button is pressed and the mouse is moving upwards, <dosomething>. There is no way to detect keyups except for saving the last key state


var isLeft: Boolean;
...
if isButton1 in Input.Mouse.States then
isLeft:= true;
else begin
if isLeft then <dosomething>
isLeft:= False;
end;

Traveler
14-10-2007, 10:54 AM
Thanks to both of you. :)
I had seen the sample, and I even considered writing something similar for the mouseup event. Somehow I kept thinking it would be something more simpler, though.

Traveler
14-10-2007, 08:16 PM
I got the thing to work now using pstudio's suggestion. :)

In case someone else is looking for something similar:

Type TMyMouseClass = Class
procedure MouseUp(X, Y: Integer; Button: Integer);
end;

procedure TMyMouseClass.MouseUp(X, Y: Integer; Button: Integer);
begin
// your mouse stuff goes here
end;

(..)
// add this to the oncreate, onInit or whatever, of your game.
with TMyMouseClass.Create do
begin
TPHXInputListener.getInstance().addMouseUpHandler( MouseUp);
end;