Continuous GUI button input

How do I make it so that when I keep holding a GUI button it keeps sending input like for moving a camera?

def create_camera_buttons(self):

    = self.create_camera_button(
    self.camera_up_button_maps, self.data_loader.camera_up_button_data)

    = self.create_camera_button(
    self.camera_down_button_maps, self.data_loader.camera_down_button_data)

    = self.create_camera_button(
    self.camera_right_button_maps, self.data_loader.camera_right_button_data)

    = self.create_camera_button(
    self.camera_left_button_maps, self.data_loader.camera_left_button_data)

def create_camera_button(self, maps, other_data):

    = DirectButton(
      = (maps.find("**/ready"), 
      = self.call_camera,
      extraArgs = other_data["move"]

  return button

def call_camera(self, pitch, turn):, turn, True)

I might suggest using the “bind” method. Specifically, I suggest binding mouse-down and mouse-up events for the buttons in question. Have the callbacks that you assign to these events set a flag to “True” and “False” respectively, indicating that the button is pressed or un-pressed. And then, in a task, check the state of the flag, and run your logic if it is.

A simple example of using “bind”, if I’m not much mistaken in it:

def makeButton(self):
    self.btn = DirectButton(text = "Button")
    self.btn.bind(DGG.B1PRESS, self.buttonPressed)

def buttonPressed(self, mousePos):
    print ("The button was pressed!")

This worked very well! Although, I did have to change a few other things around too, but hey that’s just a big part of programming in a nutshell. So, thank you for helping me, again. : )

It’s my pleasure! I’m glad that you got it working. :slight_smile:

I almost forgot to ask something. What is DGG? I typed in the search bar of the manual’s references section, but it didn’t tell me anything about it.

import direct.gui.DirectGuiGlobals as DGG

Hm. But how is it working without that particular import statement? The only thing I have that’s close to that is this:

from direct.gui.DirectGui import *

I don’t think these imports could do that:

from direct.gui.OnscreenText import OnscreenText
from direct.gui.OnscreenGeom import OnscreenGeom

The direct.gui.DirectGui module you are star-importing contains the DGG import line, so you are picking it up from there: