View previous topic :: View next topic |
Author |
Message |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Thu May 12, 2016 3:31 pm Post subject: CE bug? Tracker bar and OnClick event. (Solved) |
|
|
This issue is related to track bar and the OnClick event.
Please take a look at the screenshot.
1. Say, if the "marker arrow" (you know what I mean ) on the track bar is at "0".
2. I click the "marker arrow" and hold down mouse 1, and then move the "marker arrow" to 5, but DO NOT RELEASE MOUSE 1.
3. While still holding down mouse 1, move the mouse cursor to somewhere else, NOT ON THE TRACK BAR.
4. Now release mouse 1, the OnClick event will not be triggered.
I am using the track bar position to calculate a variable, and I found out this issue when I was trying to move "marker arrow" from the middle of the track bar to either "0" or "15". Because of the fast motion of the mouse movement, the mouse cursor often will not stay on the "marker arrow" when I release mouse 1, so the OnClick event is not triggered. Now, in order to counter that, I can only use mouse leave event, but it's not very ideal. Every time the mouse cursor hovers over the track bar and moves away, the mouse leave event is triggered.
Description: |
|
Filesize: |
10.39 KB |
Viewed: |
6751 Time(s) |

|
Last edited by Dr.Disrespect on Thu May 12, 2016 6:41 pm; edited 2 times in total |
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4691
|
Posted: Thu May 12, 2016 3:52 pm Post subject: |
|
|
That's because the OnClick event triggers only if you click on something. I wouldn't call that a bug.
Use the OnChange event instead. If you need it to take effect only when you release the mouse, use isKeyPressed(VK_LBUTTON).
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
 |
mgr.inz.Player I post too much
Reputation: 222
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Thu May 12, 2016 4:00 pm Post subject: |
|
|
That's how things work. You can cancel mouse click that way.
(hold down mouse 1 on any button, move outside, release it. Try it in other applications)
PS: you can use OnMouseUp event (if you don't like OnChange behaviour)
_________________
|
|
Back to top |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Thu May 12, 2016 4:07 pm Post subject: |
|
|
@Penguin,
The OnChange event gets triggered every time when the value changes, so if I move the marker from 15 to 1, the event will be triggered 14 times, which is not that good. The "isKeyPressed()" function is good, but how to relate it to my situation? Do I need a timer to constantly check it?
@mgr.inz.Player,
Thanks for the reply. I will try Penguin's method when I figure out how to use isKeyPressed().
Edit:
Oh, I didn't see your "PS", mgr.inz.Player. But the OnMouseUp event has four parameters, what does the "button" and "x", "y" mean?
Last edited by Dr.Disrespect on Thu May 12, 2016 4:18 pm; edited 2 times in total |
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4691
|
Posted: Thu May 12, 2016 4:09 pm Post subject: |
|
|
Wrap the contents of the OnChange function inside an if statement checking whether or not the left mouse button is held down.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Thu May 12, 2016 4:23 pm Post subject: |
|
|
ParkourPenguin wrote: | Wrap the contents of the OnChange function inside an if statement checking whether or not the left mouse button is held down. |
Do you mean something like this:
Code: |
if isKeyPressed(VK_LBUTTON) then
do something
else
do something else
end
|
But I still need something to call this "if" statement, right? I am kinda lost.... sorry.
@mgr.inz.Player
Can you explain the "button", "x" and "y" parameters in the OnMouseUp event? Thanks.
|
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4691
|
Posted: Thu May 12, 2016 4:26 pm Post subject: |
|
|
Code: | function CETrackBar1Change(sender)
if not isKeyPressed(VK_LBUTTON) then
-- code
end
end |
Alternatively, I realized you could also do it this way:
Code: | function CETrackBar1Change(sender)
if isKeyPressed(VK_LBUTTON) then return end
-- code
end |
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Thu May 12, 2016 4:28 pm Post subject: |
|
|
ParkourPenguin wrote: | Code: | function CETrackBar1Change(sender)
if not isKeyPressed(VK_LBUTTON) then
-- code
end
end |
Alternatively, I realized you could also do it this way:
Code: | function CETrackBar1Change(sender)
if isKeyPressed(VK_LBUTTON) then return end
-- code
end |
|
Oh! You are so smart. GOt your point! Thanks again.
Edit:
The code still got called 2 to 3 times after I released mouse 1, which I can't figure out why. I think I will just let it be.
|
|
Back to top |
|
 |
mgr.inz.Player I post too much
Reputation: 222
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Thu May 12, 2016 4:48 pm Post subject: |
|
|
fmanager wrote: | @mgr.inz.Player
Can you explain the "button", "x" and "y" parameters in the OnMouseUp event? Thanks. |
button - which mouse button
x and y - cursor position
you can ignore those, just use sender.Position
_________________
|
|
Back to top |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Thu May 12, 2016 4:55 pm Post subject: |
|
|
mgr.inz.Player wrote: | fmanager wrote: | @mgr.inz.Player
Can you explain the "button", "x" and "y" parameters in the OnMouseUp event? Thanks. |
button - which mouse button
x and y - cursor position
you can ignore those, just use sender.Position |
Thanks, mgr.inz.Player. I will just use (VK_LBUTTON), but with regard to x,y, is it sender.Position.x and sender.Position.y?
Edit:
Strangely, the following works perfectly:
Code: |
function CETrackBar1MouseUp(sender, VK_LBUTTON, Position)
showMessage(tostring(UDF1.CETrackbar1.Position))
end
|
Just did a little test, this also works:
Code: |
function CETrackBar1MouseUp(sender, VK_LBUTTON)
showMessage(tostring(UDF1.CETrackbar1.Position))
end
|
It looks like "x,y" can be ignored entirely.
|
|
Back to top |
|
 |
mgr.inz.Player I post too much
Reputation: 222
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Thu May 12, 2016 5:41 pm Post subject: |
|
|
VK_LBUTTON variable as function parameter? You are messing many things
Just use
Code: | function CETrackBar1MouseUp(sender, button, x, y)
showMessage(tostring(sender.Position))
end |
Lua is smart, so you can use this function too:
Code: | function CETrackBar1MouseUp(sender)
showMessage(tostring(sender.Position))
end |
_________________
|
|
Back to top |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Thu May 12, 2016 6:39 pm Post subject: |
|
|
mgr.inz.Player wrote: | VK_LBUTTON variable as function parameter? You are messing many things
Just use
Code: | function CETrackBar1MouseUp(sender, button, x, y)
showMessage(tostring(sender.Position))
end |
Lua is smart, so you can use this function too:
Code: | function CETrackBar1MouseUp(sender)
showMessage(tostring(sender.Position))
end |
|
Thanks, mgr.inz.Player.
|
|
Back to top |
|
 |
|