Bit mask in go, or a GoGTK3-problem?

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")
		}
	})

I still don’t know how I am supposed to do this, but I know that there is something seriously wrong with this line:

modifiers := uint(gtk.AcceleratorGetDefaultModMask())

It was causing other very strange problems (https://github.com/gotk3/gotk3/issues/542).

So I am closing this now, since it doesn’t seem to have anything to do with go and bitmasking. It is probably a gogtk3 problem, or more likely something wrong with my way of using it.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.