Look up specific button (ButtonPress Events in Xlib) - gcc

I'm looking for a similar function as XLookupKeysym(XKeyEvent*,int) for the ButtonPress events, so i can check what button was pressed. With XGrabButton(...) i'm getting notifications on every ButtonPress event.
How do I check for a specific button (e.g XK_Pointer_Button1) if it's pressed?

Ok, found what I wanted:
...
switch(&Event.type):
case ButtonPress:
if(Event.xbutton.button == Button1)
...
Seems to be that I've mistaken XK_Pointer_Button1 with that Button1 I used above. It's defined in X.h, not in keysymdef.h.
If found the answer here:
getting mouseclick coordinates with Xlib

XQueryPointer gives you mouse buttons state in addition to pointer coordinates

Related

Get mouse button state in OSX

Is there any way to query the state of mouse buttons in OSX? In other words, I am looking for a function that returns whether a mouse button is currently being pressed or not. The equivalent under Windows would be GetAsyncKeyState(VK_LBUTTON).
This is in the context of a Quartz event if that matters. I found the promising function CGEventSourceFlagsState that, when called with kCGEventSourceStateHIDSystemState returns that information for the CONTROL, SHIFT, ALT keys but from what I can see, unfortunately not for mouse buttons.
Seems like CGEventSourceButtonState might just be what I am looking for.

p5.js mousePressed works but doublePressed doesnot?

While programming my own minesweeper game, I have come to a stage(kind of final one) where I have to introduce the concept of Flags. Currently, I am using mousePressed() to open up any cell that might be a mine. But I cannot figure out a way how to flag any cell, as I tried to use doubleClicked() but it does not work in this case. Does anyone have any hint for this, or any built in p5.js tool that might simply flag a cell?
EDIT:
https://github.com/abj54/minesweeper
My code is in the above repo for anyone who might want to go through it. In terms of flag, it is a basic indicator of letting user guess which of the given cell may be a mine.
Listening to booth events on the same object is problematic because of the event change which is called for a dblclick:
mousedown
mouseup
click
mousedown
mouseup
click
dbclick
P5.js checks the click/dblclick event of the window so you should not use both functions (click and dblclick).
But you can use the click event with a Timeout to solve this problem.
var clicked=false, clickTimeout=300;
function mouseClicked(){
if(!clicked){
clicked=true;
setTimeout(function(){
if(clicked){
console.log("single click");
clicked=false;
//single ClickStuff
}
},clickTimeout);
}else{
clicked=false;
console.log("double click");
//double click Stuff
}
}
So you are waiting the in clickTimeout defined amount of Time if a second click is called and react to.

Difference between SelectionChange and ValueChange events of Kendo-Combobox

I have just started working on Kendo Controls in Angular. I have found an example here where its making use of both selectionChange and valueChange event. So, my question is what is the difference between these both and when to use them?
Thank you
Imagine focusing the combobox, pressing the down arrow a few times until you find what you want, and hitting enter to choose it. In this example, each press of the down arrow changes the selection, and pressing enter changes the value.

wxPython Enter Button Event

I've seen plenty of information about this topic, but not the answer to this question exactly. I have the opposite problem of most. I want to prevent the Enter button from clicking a button when the button has focus. And to do this, I don't want to simply disable the button from accepting an Enter button press, but rather I want to conditionally capture the Enter button press in a callback method. Right now, I have bound the following event to all widgets in my python program:
parent.Bind(wx.EVT_CHAR, self.CharInputCallback)
The EVT_CHAR event is actually thrown when the enter button is pressed and I'm able to get the callback in my callback method. My problem is that the enter button's functionality of virtually clicking a button still goes through, despite purposely not skipping the event (which would forward on the event). Since this is happening, and I'm sure my callback method is not forwarding the event along (I've tested this by capturing characters going to a text box) I suspect that the enter button throws an additional event that I'm not capturing. I've tried binding and capturing the additional following events to prevent the "virtual click" from the enter button:
parent.Bind(wx.EVT_TEXT_ENTER, self.CharInputCallback)
parent.Bind(wx.EVT_KEY_UP, self.CharInputCallback)
parent.Bind(wx.EVT_KEY_DOWN, self.CharInputCallback)
Yet when I press enter, the button in focus is still clicked. To summarize, is there an additional event being thrown when I press the enter button? If so, which event in particular is "virtually clicking" the button? Most forums I've found have discussed how to recognize when the enter button is pressed, but I want to recognize it and disable it's default action when a button is in focus.
I tried binding all those events to different handlers and I also bound EVT_BUTTON. It appears that EVT_BUTTON always fires BEFORE the key and char events do. If you don't want your button to be clicked, then you'll probably have to either disable it, use a different widget (maybe one of the generic buttons) or create your own. I would also ask on the wxPython mailing list to see if they have any suggestions.
The only way to order the events in wxPython that I'm aware of is to use wx.CallAfter or wx.CallLater. I'm not sure how you'd use that in this context though.
The event that causes enter to click a button is the key up event. My code for my callback was messed up slightly. Capturing the key up event and not skipping it prevent the enter button from clicking a button in focus. On Windows 7 anyways.

Attaching double click event to a label

How can I attach a "clicked" event to a label? I tried GtkEventBox but had no luck with it.
Connect to the button-press-event signal on the EventBox.
Gtk# differentiates between Widgets and 'Containers'. Most widgets placed on a Gtk# form will NOT receive mouse click events. In order to receive a mouse event you need to place the widget inside a specific container - like EventBox:
Add an EventBox containter to your form. You can place it behind other Widgets or since it is not visible, unless you specifically select it to be (or change its background color).
Put your label widget inside this EventBox. Notice that the label will get the shape and size of the EventBox.
Add to this EventBox the signal 'ButtonPressEvent' out of the "Common Widget Signals".
If you need to identify the button that was clicked while handling this event, use the uint value in: args.Event.Button typically '1' will be the left mouse button, '2' the center button and '3' the right button ('2' might be also when both left and right buttons are clicked).
It seems you don't need EventBox at all: Since the problem is that labels don't have any associated X11 window, just give it one with set_has_window(True)! The following works for me:
self.label = Gtk.Label()
self.label.set_has_window(True)
self.label.set_events(Gdk.EventMask.BUTTON_PRESS_MASK)
self.label.connect("button-press-event", self.click_label)
The documentation says it should only be used for implementing widgets - but hey, it works. Who cares about "should"?
2019-04-17 Update:
ptomato here is right, GtkLabel is one of the exceptions that indeed requires an eventbox, so you should connect to the button-press-event signal of the eventbox. For other widgets, the set/add events APIs in my original answer should be still relevant.
Original (wrong) answer:
Connect to the button-press-event signal, but directly on the GtkLabel. I'd say you don't need an eventbox here, as GtkLabel already inherits this signal from GtkWidget. To enable the GtkLabel to receive those events, you need first to call gtk_widget_set_events or gtk_widget_add_events, and add the sensitivity to the GDK_BUTTON_PRESS_MASK event.

Resources