Ejemplo n.º 1
0
        static Gdk.EventKey CreateKeyEvent(uint keyval, int keyCode, Gdk.ModifierType state, Gdk.EventType eventType, Gdk.Window win)
        {
            int effectiveGroup, level;

            Gdk.ModifierType cmods;
            if (keyval == 0)
            {
                Gdk.Keymap.Default.TranslateKeyboardState((uint)keyCode, state, 0, out keyval, out effectiveGroup, out level, out cmods);
            }

            Gdk.KeymapKey [] keyms = Gdk.Keymap.Default.GetEntriesForKeyval(keyval);
            if (keyms.Length == 0)
            {
                return(null);
            }

            var nativeEvent = new NativeEventKeyStruct {
                type             = eventType,
                send_event       = 1,
                window           = win != null ? win.Handle : IntPtr.Zero,
                state            = (uint)state,
                keyval           = keyval,
                group            = (byte)keyms [0].Group,
                hardware_keycode = keyCode == -1 ? (ushort)keyms [0].Keycode : (ushort)keyCode,
                length           = 0,
                time             = global::Gtk.Global.CurrentEventTime
            };

            IntPtr ptr = GLib.Marshaller.StructureToPtrAlloc(nativeEvent);

            return(new EventKeyWrapper(ptr));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Used internally - sends a keypress event to a widget.
        /// </summary>
        /// <param name="target">Target widget.</param>
        /// <param name="keyVal">Key value being sent.</param>
        /// <param name="state">Key press state - e.g. ctrl click.</param>
        /// <param name="eventType">Type of event to be sent.</param>
        private static void SendKeyEvent(Widget target, uint keyVal, ModifierType state, EventType eventType)
        {
            Gdk.KeymapKey[] keyms = Gdk.Keymap.Default.GetEntriesForKeyval(keyVal);
            if (keyms.Length == 0)
            {
                throw new Exception("Keyval not found");
            }

            Gdk.Window win = target.GdkWindow;

            var nativeEvent = new NativeEventKeyStruct
            {
                type             = eventType,
                send_event       = 1,
                window           = win.Handle,
                state            = (uint)state,
                keyval           = keyVal,
                group            = (byte)keyms[0].Group,
                hardware_keycode = (ushort)keyms[0].Keycode,
                length           = 0,
                time             = Gtk.Global.CurrentEventTime
            };

            IntPtr ptr = GLib.Marshaller.StructureToPtrAlloc(nativeEvent);

            try
            {
                Gdk.EventHelper.Put(new Gdk.EventKey(ptr));
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
            }
        }
Ejemplo n.º 3
0
        void SendKeyEvent(Gtk.Widget target, uint keyval, Gdk.ModifierType state, Gdk.EventType eventType, string subWindow)
        {
            Gdk.KeymapKey[] keyms = Gdk.Keymap.Default.GetEntriesForKeyval(keyval);
            if (keyms.Length == 0)
            {
                throw new Exception("Keyval not found");
            }

            Gdk.Window win = target.GdkWindow;

            // FIXME: Do we need subwindow for anything?

            /*
             * if (subWindow == null) {
             *      win = target.GdkWindow;
             * } else {
             *      win = (Gdk.Window)GetValue (target, target.GetType (), subWindow);
             * }
             */

            var nativeEvent = new NativeEventKeyStruct {
                type             = eventType,
                send_event       = 1,
                window           = win.Handle,
                state            = (uint)state,
                keyval           = keyval,
                group            = (byte)keyms [0].Group,
                hardware_keycode = (ushort)keyms [0].Keycode,
                length           = 0,
                time             = Gtk.Global.CurrentEventTime
            };

            IntPtr ptr = GLib.Marshaller.StructureToPtrAlloc(nativeEvent);

            try {
                Gdk.EventHelper.Put(new Gdk.EventKey(ptr));
            } finally {
                Marshal.FreeHGlobal(ptr);
            }
        }
Ejemplo n.º 4
0
		void SendKeyEvent (Gtk.Widget target, uint keyval, Gdk.ModifierType state, Gdk.EventType eventType, string subWindow)
		{
			Gdk.KeymapKey[] keyms = Gdk.Keymap.Default.GetEntriesForKeyval (keyval);
			if (keyms.Length == 0)
				throw new Exception ("Keyval not found");

			Gdk.Window win = target.GdkWindow;

			// FIXME: Do we need subwindow for anything?
			/*
			if (subWindow == null) {
				win = target.GdkWindow;
			} else {
				win = (Gdk.Window)GetValue (target, target.GetType (), subWindow);
			}
			*/

			var nativeEvent = new NativeEventKeyStruct {
				type = eventType,
				send_event = 1,
				window = win.Handle,
				state = (uint)state,
				keyval = keyval,
				group = (byte)keyms [0].Group,
				hardware_keycode = (ushort)keyms [0].Keycode,
				length = 0,
				time = Gtk.Global.CurrentEventTime
			};

			IntPtr ptr = GLib.Marshaller.StructureToPtrAlloc (nativeEvent); 
			try {
				Gdk.EventHelper.Put (new Gdk.EventKey (ptr));
			} finally {
				Marshal.FreeHGlobal (ptr);
			}
		}
Ejemplo n.º 5
0
        static Gdk.EventKey CreateKeyEvent(uint keyval, int keyCode, Gdk.ModifierType state, Gdk.EventType eventType, Gdk.Window win)
        {
            int effectiveGroup, level;
            Gdk.ModifierType cmods;
            if (keyval == 0)
                Gdk.Keymap.Default.TranslateKeyboardState ((uint)keyCode, state, 0, out keyval, out effectiveGroup, out level, out cmods);

            Gdk.KeymapKey [] keyms = Gdk.Keymap.Default.GetEntriesForKeyval (keyval);
            if (keyms.Length == 0)
                return null;

            var nativeEvent = new NativeEventKeyStruct {
                type = eventType,
                send_event = 1,
                window = win != null ? win.Handle : IntPtr.Zero,
                state = (uint)state,
                keyval = keyval,
                group = (byte)keyms [0].Group,
                hardware_keycode = keyCode == -1 ? (ushort)keyms [0].Keycode : (ushort)keyCode,
                length = 0,
                time = global::Gtk.Global.CurrentEventTime
            };

            IntPtr ptr = GLib.Marshaller.StructureToPtrAlloc (nativeEvent);
            return new EventKeyWrapper (ptr);
        }