GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Nov 01, 2014 9:43 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Map a GtkButton to a keyval to act as real keyboard button
PostPosted: Tue Oct 02, 2007 1:05 am 
Offline
Familiar Face

Joined: Fri Sep 21, 2007 6:14 am
Posts: 5
Hi all,

How do I keybind or map a gtkbutton to a keyboard button?
I am trying to create up and down arrows that work the same(send and receieve same signals) as the keyboard up and down arrows.


Thank you very much you advance.

Rgds,
Boone.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 02, 2007 3:15 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
You may want to capture the GtkWindow "key-press-event" of your application, and if it's the up or down arrow, call your GtkButton's clicked signal callback.

This example: Capture "Enter" key in a GtkCombo box shows catching an enter keypress. You could probably modify it from there.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 02, 2007 11:01 pm 
Offline
Familiar Face

Joined: Fri Sep 21, 2007 6:14 am
Posts: 5
Thank you! Thought no one would bother to reply. I appreciate it very much.


Actually, what I wanted to do is the other way round. click the button and it will emit a up/down key-press-event signal as during actual operation there won't be any keyboards. Is it possible? Can I emit a specific key-press-event signal? Sorry if I wasnt clear.

Thank you again.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 02, 2007 11:35 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Do you want that signal to be emitted in your application or in some other application? That could be a problem. That is-- are you trying to create a sort of virtual keyboard?

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 03, 2007 12:16 am 
Offline
Familiar Face

Joined: Fri Sep 21, 2007 6:14 am
Posts: 5
I would want that signal to be emitted in my application and yup,sort of like a virtual keyboard.

I'd like my buttons to emulate the keypresses for up,down and enter.

I know I could write the code to do up,down and enter for each of this buttons somehow but I reckon it would be so much easier and more efficient if I could just emulate those specific key-presses rather than figuring which widget to focus next, how to navigate up/down,etc..


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 03, 2007 1:29 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
That's a little tricky. I'm not entirely sure... what I'm thinking is that say the user had a the cursor in a text box. While you could send the up keypress to that signal, clicking the button to do so would change focus to that button they pressed to do it instead.

Although, if this virtual keyboad is only going to be for your GTK+ application, I think you could do it by finding out where focus is and sending that widget the up keypress.

I'm not entirely sure though. You'll have to dink around.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 04, 2007 12:58 am 
Offline
Familiar Face

Joined: Fri Sep 21, 2007 6:14 am
Posts: 5
I finally did it. I searched all over and found an example.

http://www.mail-archive.com/pygtk@daa.com.au/msg12216.html

The code snippet was in phyton language though. I rewrote it in C and it worked for me as well. All there was to do was to create an event which has the same keyval and keycode properties as the real keyboard key ones and emit that signal when the button is clicked.

Thanks ALOT anyways for your time and thoughts.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group