* GTK key-press-event
@ 2016-11-02 9:19 hreba
2016-11-02 9:45 ` Dmitry A. Kazakov
0 siblings, 1 reply; 3+ messages in thread
From: hreba @ 2016-11-02 9:19 UTC (permalink / raw)
Hi,
I am trying to write a key press handler with user data. I know how to
connect the handler and that its type is
type Handler is access procedure
Widget : access Widget_Type'Class;
Params : Glib.Values.GValues;
User_Data : User_Type);
What I don't know is how to get the key which was pressed.
A few months ago I had a similar problem where I needed a Cairo Graphics
context, and I got it from the parameter list "Params" , selecting the
first component with Glib.Values.Nth(), and converting that with
Cairo.Get_Context.
Does anybody know how to get Gdk_Event_Key (which contains the
information about the pressed key)?
--
Frank Hrebabetzky +49 / 6355 / 989 5070
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: GTK key-press-event
2016-11-02 9:19 GTK key-press-event hreba
@ 2016-11-02 9:45 ` Dmitry A. Kazakov
2016-11-02 16:26 ` hreba
0 siblings, 1 reply; 3+ messages in thread
From: Dmitry A. Kazakov @ 2016-11-02 9:45 UTC (permalink / raw)
On 02/11/2016 10:19, hreba wrote:
> I am trying to write a key press handler with user data. I know how to
> connect the handler and that its type is
>
> type Handler is access procedure
> Widget : access Widget_Type'Class;
> Params : Glib.Values.GValues;
> User_Data : User_Type);
There is a typed marshaller for handing this type of events:
type Handler is access function
( Widget : access Gtk_Widget_Record'Class;
Event : Gdk_Event;
User_Data : User_Type
) return Boolean;
> What I don't know is how to get the key which was pressed.
The event parameter contains input event type and if that was a keyboard
event, the key pressed/released:
case Get_Event_Type (Event) is
when Key_Press => -- This a key-press event
case Get_Key_Val (Event) is
when GDK_Insert => -- This is INSERT key
...
> A few months ago I had a similar problem where I needed a Cairo Graphics
> context, and I got it from the parameter list "Params" , selecting the
> first component with Glib.Values.Nth(), and converting that with
> Cairo.Get_Context.
You could use Nth () but there is no reason doing that. And for this
type of event there is a return value.
Note that key press events must be unmasked to be emitted. Then some
widgets never emit these events anyway. They must be wrapped into an
"event-box" which itself is invisible but emits the events.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: GTK key-press-event
2016-11-02 9:45 ` Dmitry A. Kazakov
@ 2016-11-02 16:26 ` hreba
0 siblings, 0 replies; 3+ messages in thread
From: hreba @ 2016-11-02 16:26 UTC (permalink / raw)
On 11/02/2016 10:45 AM, Dmitry A. Kazakov wrote:
> On 02/11/2016 10:19, hreba wrote:
>
>> I am trying to write a key press handler with user data. I know how to
>> connect the handler and that its type is
>>
>> type Handler is access procedure
>> Widget : access Widget_Type'Class;
>> Params : Glib.Values.GValues;
>> User_Data : User_Type);
>
> There is a typed marshaller for handing this type of events:
>
> type Handler is access function
> ( Widget : access Gtk_Widget_Record'Class;
> Event : Gdk_Event;
> User_Data : User_Type
> ) return Boolean;
>
>> What I don't know is how to get the key which was pressed.
>
> The event parameter contains input event type and if that was a keyboard
> event, the key pressed/released:
>
> case Get_Event_Type (Event) is
> when Key_Press => -- This a key-press event
> case Get_Key_Val (Event) is
> when GDK_Insert => -- This is INSERT key
> ...
>
>> A few months ago I had a similar problem where I needed a Cairo Graphics
>> context, and I got it from the parameter list "Params" , selecting the
>> first component with Glib.Values.Nth(), and converting that with
>> Cairo.Get_Context.
>
> You could use Nth () but there is no reason doing that. And for this
> type of event there is a return value.
>
> Note that key press events must be unmasked to be emitted. Then some
> widgets never emit these events anyway. They must be wrapped into an
> "event-box" which itself is invisible but emits the events.
>
It works now. My widget is a DrawingArea. In addition to unmasking the
key press event, the "can focus" flag must be set. An event box was not
necessary.
Thanks for your help.
--
Frank Hrebabetzky +49 / 6355 / 989 5070
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-11-02 16:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-02 9:19 GTK key-press-event hreba
2016-11-02 9:45 ` Dmitry A. Kazakov
2016-11-02 16:26 ` hreba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox