This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
TheOddByte's profile picture

Monitor Event: Drag

Started by TheOddByte, 01 August 2013 - 08:14 AM
TheOddByte #1
Posted 01 August 2013 - 10:14 AM
I've been looking through the wiki and it doesn't seem like the drag event does exist for monitors..
Correct me if I'm wrong though, But wouldn't a monitor_drag event be useful?
This would be nice if you are creating an adventure map with computercraft monitors that you could have puzzles on.
That's just one idea I have of it, But ofcourse it's you moderators who decides :)/>
Cranium #2
Posted 01 August 2013 - 10:53 AM
This isn't really possible for monitors, considering all you are doing is clicking multiple times, and not exactly 'dragging' your hand across the screen. If you see your arm, when you hold the right/left click, it just keeps swinging on the screen.
Sebra #3
Posted 01 August 2013 - 11:28 AM
And can it be changing? May be with help of some item.
Cozzimoto #4
Posted 01 August 2013 - 03:32 PM
ive seen where a window you want to move is easy by clicking somewhere on the window you want to move and click where you want it to go and boom roasted in one redraw event.
Geforce Fan #5
Posted 12 August 2013 - 10:50 PM
To me, this would seem like a good idea, it would add much more cross-compatibility support for running apps that are normally for computers on monitors. Maybe make an item that triggers the drag event, or holding something like cmd, but not control because that is how macbooks right-click
svdragster #6
Posted 16 August 2013 - 01:17 PM
That would make paint on monitors easier to use.
theoriginalbit #7
Posted 16 August 2013 - 03:37 PM
What people don't seem to be understanding here is that MINECRAFT is not capable of performing this action! We can do it in GUIs, but we cannot do it in the world because of the fact that our hand "returns" when we interact with things.
svdragster #8
Posted 16 August 2013 - 04:51 PM
What people don't seem to be understanding here is that MINECRAFT is not capable of performing this action! We can do it in GUIs, but we cannot do it in the world because of the fact that our hand "returns" when we interact with things.
Are you sure? Is it not just how it looks? Because if you keep holding right mousebutton and pointing at a button, it also keeps being pressed.
But that could also be because it presses the button before it returns back to the unpressed position… hm.
theoriginalbit #9
Posted 16 August 2013 - 05:07 PM
Are you sure? Is it not just how it looks?
Positive. There was a reason I said "returns" in quotes. The way Minecraft is designed you can only `punch` things (with an empty hand), not continuously `touch` them. I just say do it programatically.

For example there is no way to add right-clicking to the monitors (as you right-click to touch the monitor), however through some programming trickery we can semi-emulate a right-click…
brett122798 #10
Posted 17 August 2013 - 03:15 PM
Positive. There was a reason I said "returns" in quotes. The way Minecraft is designed you can only `punch` things (with an empty hand), not continuously `touch` them. I just say do it programatically.

Positive about that? Bukkit has the PlayerInteractEvent in it's API, which triggers whenever a player left/right clicks. It also constantly triggers if you're holding down the right click. That must mean that the client is sending data to the server saying "Hey, I'm holding down the right mouse button."
svdragster #11
Posted 17 August 2013 - 06:30 PM
Positive. There was a reason I said "returns" in quotes. The way Minecraft is designed you can only `punch` things (with an empty hand), not continuously `touch` them. I just say do it programatically.

Positive about that? Bukkit has the PlayerInteractEvent in it's API, which triggers whenever a player left/right clicks. It also constantly triggers if you're holding down the right click. That must mean that the client is sending data to the server saying "Hey, I'm holding down the right mouse button."
I think it's not holding. If you hold the mousebutton it triggers the RightClickHook instantly(idk about bukkit, I'm developing with CanaryMod).
immibis #12
Posted 17 August 2013 - 09:07 PM
Positive. There was a reason I said "returns" in quotes. The way Minecraft is designed you can only `punch` things (with an empty hand), not continuously `touch` them. I just say do it programatically.

Positive about that? Bukkit has the PlayerInteractEvent in it's API, which triggers whenever a player left/right clicks. It also constantly triggers if you're holding down the right click. That must mean that the client is sending data to the server saying "Hey, I'm holding down the right mouse button."
It just sends repeated right clicks. You can't tell between someone spamming right click, and someone holding it.
theoriginalbit #13
Posted 18 August 2013 - 01:58 AM
Positive about that? Bukkit has the PlayerInteractEvent in it's API, which triggers whenever a player left/right clicks. It also constantly triggers if you're holding down the right click. That must mean that the client is sending data to the server saying "Hey, I'm holding down the right mouse button."
100% positive… There are 2 keywords you just said there… Bukkit — well Bukkit doesn't count, ignoring the fact that it is riddled with bugs and is one of the dirtiest instances of Minecraft you can go with these days, CC isn't developed for Bukkit, it is developed for Forge! … The second keyword(s) you said there is "constantly triggers", spamming is different from holding, in LWJGL when checking for mouse drag on a GUI, you don't check for a spamming of events, there is actually a mouse drag event! Such an event that cannot be used/checked for outside of a GUI because of the methods that Minecraft supply…
brett122798 #14
Posted 18 August 2013 - 12:53 PM
100% positive… There are 2 keywords you just said there… Bukkit — well Bukkit doesn't count, ignoring the fact that it is riddled with bugs and is one of the dirtiest instances of Minecraft you can go with these days, CC isn't developed for Bukkit, it is developed for Forge! … The second keyword(s) you said there is "constantly triggers", spamming is different from holding, in LWJGL when checking for mouse drag on a GUI, you don't check for a spamming of events, there is actually a mouse drag event! Such an event that cannot be used/checked for outside of a GUI because of the methods that Minecraft supply…
I'm not talking about Bukkit at all, I'm using it to prove there's a way to achieve this dragging thing still without any modifications. It's certainly possible to check for a mass amount of right clicking and have it trigger the drag event. But, it isn't the most efficient way of doing so(might be slightly buggy). It still isn't so far fetched for the CC developer to add some sort of event when you hold your left/right mouse buttons when looking at a monitor.

In the meantime, try to write up some code that works with my theory.
PixelToast #15
Posted 18 August 2013 - 03:51 PM
well, you can technically detect if the user held down right click between the times your player "clicked" the screen
but that is as reliable lua side as it is java
take the frequency you can tap a monitor, if the os.time was greater than the last + frequency then it wasnt dragged
this dosent compensate for client lag so it would be verry buggy

bukkit has nothing to do with this, shoo theoriginalbit there are obviously functions in forge for this too
oeed #16
Posted 18 August 2013 - 05:57 PM
Dragging is possible to implement, take PearOS as an example, but a drag event would be useful. Even if it was just a wrapper of some sorts.
Cloudy #17
Posted 18 August 2013 - 06:20 PM
Would any of you guys say it was possible to code this in Lua, based on the repeated click events?
oeed #18
Posted 18 August 2013 - 06:22 PM
Would any of you guys say it was possible to code this in Lua, based on the repeated click events?

Yes, I've done it.
theoriginalbit #19
Posted 18 August 2013 - 08:20 PM
Would any of you guys say it was possible to code this in Lua, based on the repeated click events?
Yes, 100% possible.
oeed #20
Posted 18 August 2013 - 08:49 PM
Essentially,

What a player touches the screen you set a table (called clickLocation in this example) to the co-ordinates of the click (e.g. {x: 4, y: 6}). You then start a timer to a time that is just over the time it takes for the player to send another touch event if they are holding the mouse. If another touch happens while the timer is running you reset the timer and clickLocation. When the user stops dragging the timer event happens, so you could call a drag event or run a function with the coordinates of clickLocation.

Here's some non tested example code:

There's probably a typo or error in it, but you get the general idea. Again, I haven't tested it, but it should work. It only fires when the drag is complete, but you could easily change it so it fired on every move.


local dragStartLocation = {}
local clickLocation = {}
local dragTimer = nil

while true do
  local event, arg1, arg2, arg3, arg4 = os.pullEvent()
  if event == "monitor_touch" then
   if not dragStartLocation then
	 dragStartLocation = {x: arg2, y: arg3}
   end
	clickLocation = {x: arg2, y: arg3}
	dragTimer = os.startTimer(0.1) --i havent tested this value, it will need experimentation
  elseif event == "timer" and arg1 == dragTimer then
	os.queueEvent("monitor_drag",dragStartLocation["x"], dragStartLocation["y"], clickLocation["x"], clickLocation["y"])
  elseif event == "monitor_drag" then
	print("Drag from ("..arg1..", "..arg2..") to ("..arg1..", "..arg2..")")
  end
end
Cloudy #21
Posted 19 August 2013 - 01:21 AM
Then do it then. It would be just as easy for you to do it as it would be us.
Engineer #22
Posted 27 August 2013 - 02:00 AM
I'm sorry, but you guys are really missing something. You can only touch the monitor, therefor if you write a program where you "drag", you still are touching the monitor.continuously.
So there is no dragging involved.