Get mouse coordinates in a loop
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 04/08/2012 at 08:06, xxxxxxxx wrote:
Hi everyone!
I'm working on a ToolData Plugin and need to to implement a loop that continues to give me the current mouse position in the editor until I click a mouse button. Basically I want something that behaves like the inverse of a MouseDrag.
The loop that has gotten me closest to what I want so far looks like this:while not msg[c4d.BFM_INPUT_MOUSELEFT]: #Mouse button clicked?
mouseX = msg[c4d.BFM_INPUT_X]
mouseY = msg[c4d.BFM_INPUT_Y]
print "X: ", mouseX, "Y: ",mouseY
win.BfGetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_MOUSELEFT, msg)#Store Input State to msgThe loop is happening inside the MouseInput() procedure of the ToolData class so 'win' is the current editor view and 'msg' a basecontainer to store the Input Events. So far I didn't have any luck getting this to work. The console outputs the mouse coordinates in screen space, but I can't exit the loop by clicking. Also C4D hangs after the loop has been running for a while.
On a side note, I think there is an error in the documentation because BfGetInputState actually takes two arguments (the flag and a BaseContainer to store the Input Events) and returns a bool instead of a BaseContainer. It's basically the same as c4d.gui.GetInputState(). Took me a while to figure this out, but it didn't help much in the endI hope someone can has a clue how to work this out! Thanks!
Jo
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 04/08/2012 at 09:52, xxxxxxxx wrote:
Okay, I've found the answer myself. It was right under my nose the whole time.
At the bottom of the Input Events page in the Python documentation I found this nifty piece of code:state=c4d.BaseContainer()
while gui.GetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_MOUSELEFT, state) :
if state.GetLong(c4d.BFM_INPUT_VALUE)==0: breakx=state.GetLong(c4d.BFM_INPUT_X)
y=state.GetLong(c4d.BFM_INPUT_Y)I switched the if statement to check for 1 instead of 0 and I'm good to go. I should take more walks between coding sessions.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 06/08/2012 at 00:53, xxxxxxxx wrote:
What I still don't get is why I always have to ask for a specific input event. While this may be more efficient sometimes you want to check for more than one event to occur. Of course I can stack a number of GetInputState calls in a while loop, but wouldn't it be best if I could just get a BaseContainer that includes a snapshot of all possible Events at a certain time?
I thought GetInputEvent would do exactly that, but while this is true for the various mouse buttons pressed, it doesn't give you the X Y coordinates of the mouse.Here an example:
while True:
gui.GetInputEvent(c4d.BFM_INPUT_MOUSE, msg)
if msg[c4d.BFM_INPUT_CHANNEL]==c4d.BFM_INPUT_MOUSELEFT: break
if msg[c4d.BFM_INPUT_CHANNEL]==c4d.BFM_INPUT_MOUSERIGHT: break
mouseX=msg[c4d.BFM_INPUT_X]
mouseY=msg[c4d.BFM_INPUT_Y]
print "X: ",mouseX," Y: ",mouseYThis loop will exit when the left or right mouse button is pressed, but BFM_INPUT_X and BFM_INPUT_Y output to None.
I can live with my earlier approach of using GetInputState but I was just curious why the more "elegant" way with GetInputEvent fails on giving me the coordinates. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 06/08/2012 at 08:36, xxxxxxxx wrote:
gui.GetInputEvent() returns True and the mouse position (containers filled) only when a mouse button is clicked. When the mouse is moving it returns False. I'll ask the developers why.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 06/08/2012 at 09:19, xxxxxxxx wrote:
Thanks Yannik, that would help. Maybe while you are at it you could check out the BfGetInputEvent() and BfGetInputState() procedures from the EditorWindow class. BfInputEvent() has the same strange behavior as InputEvent() and the documentation seems to be wrong (arguments and return values should be the same as InputEvent() and InputState()).
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 06/08/2012 at 09:34, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Maybe while you are at it you could check out the BfGetInputEvent() and BfGetInputState() procedures from the EditorWindow class. BfInputEvent() has the same strange behavior as InputEvent() and the documentation seems to be wrong (arguments and return values should be the same as InputEvent() and InputState()).
Thanks for reporting that. I'll fix these errors.