check if button is held down?

There is already a class providing this functionality, and it can be found via the API documentation: InputState. It works for keyboard keys and mouse buttons.

from direct.showbase.InputStateGlobal import inputState

inputState.watchWithModifiers('attack', 'mouse1')
inputState.watchWithModifiers('forward', 'w')

def myTask(task):
  print inputState.isSet('attack')
  print inputState.isSet('forward')
  return task.cont