[Gtk-sharp-list] How to set the fields of properties of Gdk.Event
Christian Hoff
christian_hoff at gmx.net
Tue Dec 8 12:53:50 EST 2009
Matt Guo wrote:
> I want to send a mouse event to a given window. The C code for this
> would be like:
>
> bool SendMousePress (MouseButton type, x, y) {
> GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS);
> event->button.button = type == LEFT ? 1 : (type == MIDDLE ? 2 : 3);
> event->button.x = x;
> event->button.y = y;
> ... //other event fields setting
> gdk_event_put(event);
> gdk_event_free(event);
> }
>
> The problem I have now is that though I can replace "gdk_event_new",
> "gdk_event_put" and "gdk_event_free" with Gdk.EventHelper.New,
> Gdk.EventHelper.Put
> and Gdk.EventHelper.Free, but how can I set the event fields with
> gdk-sharp? Since all properties in the Gdk.Event class are read-only.
>
Thanks to Mike, the properties are now read-write in Gtk# trunk. If you
want to do the same in 2.12, try something like:
[StructLayout (LayoutKind.Sequential)]
struct NativeEventButtonStruct {
EventType type;
IntPtr window;
sbyte send_event;
public uint time;
public double x;
public double y;
public IntPtr axes;
public uint state;
public uint button;
public IntPtr device;
public double x_root;
public double y_root;
}
NativeEventButtonSTruct native_event_button = new
NativeEventButtonStruct ();
native_event_button.x/y = ...;
IntPtr struct_ptr =Glib.Marshaller.Malloc (sizeof
(NativeButtonEventStruct));
Marshal.StructureToPtr (strct_ptr, native_event_button);
EventButton evnt = new EventButton (struct_ptr);
Gdk.EventHelper.Put (evnt);
Free (evnt);
Hope this helps to get you started,
Christian
More information about the Gtk-sharp-list
mailing list