I am trying to detect when the control key is pressed in a GTK application using the key-press-event. This page seem to show roughly how to do this (in C):
https://developer.gnome.org/gtk3/stable/checklist-modifiers.html
This is the code I have so far, but it does not work. I am starting to think that I am not doing the bit masking correct at row 5 (keyEvent.KeyVal() & modifiers). Is this how you do a bit mask in go? Or maybe I am not understanding the C code correctly…
// Connect to the key press event
win.Connect("key-press-event", func(window *gtk.Window, event *gdk.Event) {
keyEvent := gdk.EventKey{Event: event}
modifiers := uint(gtk.AcceleratorGetDefaultModMask())
isControlPressed := (keyEvent.KeyVal()&modifiers == gdk.GDK_CONTROL_MASK)
if isControlPressed {
fmt.Printf("Control is pressed")
}
})