Is it possible to simulate a mouse click on a button.
For example I have a button and I put my mouse on this button. When I press the key “j” on my keyboard, it simulates the click and launch the function that corresponds to the button click.
Thanks,
Julien
I’m french, sorry for my english…
messenger.send(“button_name”)
where “button name” is the string you listen to.
I don’t understand what you want I do…
My code :
import direct.directbase.DirectStart
from direct.gui.DirectGui import *
from direct.showbase.DirectObject import DirectObject
from pandac.PandaModules import TextNode
class DemoMouse(DirectObject):
def click(self):
print('click')
messenger.send(self.b)
def __init__(self):
self.accept("j",self.click)
def setText():
print("Button Clicked")
self.b = DirectButton(text = ("OK", "click!", "rolling over", "disabled"),
scale=.05, command=setText)
self.b.accept('clickOnb',setText)
run()
DemoMouse()
When I click on “j” and if the mouse is on the button, the function setText is called.
In other words, I want change the button of the click. My mouse button become my “j” key
[/quote]
croxis
February 13, 2010, 3:07pm
4
You might want to look at Collision Detection . [/url]
drwr
February 13, 2010, 4:16pm
5
So, you’re asking about a DirectButton specifically. To make a DirectButton respond to a keyboard button instead of (or in addition to) the mouse button, you can do:
myButton.guiItem.addClickButton(KeyboardButton.asciiKey('j'))
myButton.bind('click-j-', myButton.commandFunc)
This is untested, but I think it should work.
David
Oops. Looks like i misunderstood the question first.
And thanks to David for the neat snippet.