GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Map a GtkButton to a keyval to act as real keyboard button

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
bhtan
Familiar Face


Joined: 21 Sep 2007
Posts: 5

PostPosted: Tue Oct 02, 2007 1:05 am    Post subject: Map a GtkButton to a keyval to act as real keyboard button Reply with quote

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.
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 505
Location: Portland, OR USA

PostPosted: Tue Oct 02, 2007 3:15 pm    Post subject: Reply with quote

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.
Back to top
bhtan
Familiar Face


Joined: 21 Sep 2007
Posts: 5

PostPosted: Tue Oct 02, 2007 11:01 pm    Post subject: Reply with quote

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.
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 505
Location: Portland, OR USA

PostPosted: Tue Oct 02, 2007 11:35 pm    Post subject: Reply with quote

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?
Back to top
bhtan
Familiar Face


Joined: 21 Sep 2007
Posts: 5

PostPosted: Wed Oct 03, 2007 12:16 am    Post subject: Reply with quote

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..
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 505
Location: Portland, OR USA

PostPosted: Wed Oct 03, 2007 1:29 pm    Post subject: Reply with quote

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.
Back to top
bhtan
Familiar Face


Joined: 21 Sep 2007
Posts: 5

PostPosted: Thu Oct 04, 2007 12:58 am    Post subject: Reply with quote

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.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP