Getting keyboad input.

Need help, or want to share a macro? Post here!
User avatar
davecoventry
Posts: 94
Joined: Mon Dec 09, 2013 8:11 pm
Location: Johannesburg
Contact:

Getting keyboad input.

Postby davecoventry » Wed Mar 15, 2017 11:01 am

I have this, but it's not working.

Code: Select all

basepoint=None
def pointHandler(val,point):
  global basepoint
  global mw
  if val==0:
    basepoint=point
  else:
    dx=point.x-basepoint.x
    dy=point.y-basepoint.y
    dz=point.z-basepoint.z
    print "dx=\n",dx
    print "dy=\n",dy
    print "dz=\n",dz


class pointSnapper:
  def __init__(self,val,p=None):
    self.point = None
    self.val=val
    FreeCADGui.Snapper.getPoint(last=p,callback=self.clicked)
    self.call = self.view.addEventCallback("SoEvent",self.action)
  def clicked(self,point,extra):
    self.point = point
    if self.val==1:
      pointHandler(0,point)
      pointSnapper(2,point)
    else:
      pointHandler(1,point)
  def action(self,arg):
    if arg["Type"] == "SoKeyboardEvent":
      if arg["Key"] == "ESCAPE":
        self.finish()
      print arg["Key"]


s = pointSnapper(1)


I want to be able to accept keyboard input, so if the user presses "X", I know he's looking for a point in the X-direction.

The code above doesn't print out the arg["Key"]
~ Dave