Click and Release

I am trying to register mouse clicks and releases.

I am clearly missing something here.

Could someone please take a look at this and offer any suggestions, please.
:expressionless:

from Blender.Draw import *
from Blender.BGL import *

def gui():
   Button("Exit", 1234, 75, 10, 60, 25, "Q")

def event(evt, val):
   print evt, val
###This line should print down When LMB_Click
   if (evt == 1.1 and val ):
      print "Down"
###This line should print up when LMB_Release
   if (evt == 1.0  and val):
      print "Up"

   if (evt == QKEY and val):
      Exit()

def bevent(evt):
   if (evt == 1234):
      Exit()
print "New"
Register(gui, event, bevent)

When I run this the 1,1 event says “Up”(should’nt that say down) and the 1,0 event says nothing.

I don’t think you understand how event callback works.

evt is the index of the event. For readability, you really should use the corresponding variables in the Draw module (Blender.Draw.LEFTMOUSE for example)
val is the value associated with the event. When the event is a toggle (keyboard, mouse buttons), it takes the values 1 (pressed) or 0 (released). For the mouse motion (MOUSEX and MOUSEY), it takes numerical values (as you should know :wink: ).

So, if I rewrite it correctly, it should be:

from Blender.Draw import * 
from Blender.BGL import * 

def gui(): 
   Button("Exit", 1234, 75, 10, 60, 25, "Q") 

def event(evt, val): 
   print evt, val 
###This line should print down When LMB_Click 
   if (evt == LEFTMOUSE and val): 
      print "Down" 
###This line should print up when LMB_Release 
   if (evt == LEFTMOUSE  and not val): 
      print "Up" 

   if (evt == QKEY and val): 
      Exit() 

def bevent(evt): 
   if (evt == 1234): 
      Exit() 

Register(gui, event, bevent)

you’ll see here that I used “not val” and “val” instead of “val == 1” and “val == 0”. That is because Python uses the truth value of an object if it is not in a conditional boolean (=, >, …). And integer is TRUE if it is not 0. The NOT keyword only tells Python to check if the following condition is FALSE instead of the usual.

hope that helps

Martin

Helps immensly, Many Thanks Theeth.