Re: keyboard events handling



On Fri, 27 Feb 2009 10:31:27 +0530
nishit sharma <sharmafrequent gmail com> wrote:

>Hi All,
>
>I am able to handle 1-9 key and a-z key events on the focus widget by
>filling GdkKeyEvent members but failed in handling events for special keys
>like Tab, Caps Lock
>etc.
>
>Can anybody tell me how i can handle these events or any link which i can
>refer to make my job working.
>
>I have filled the members of this structure according to the values but when
>i tried for Tab key it failed and it doesn't  focus on other widgets.
>
>Waiting for your replies.
>
>Thanks and Regards

I'm having trouble translating your English. Are you trying to capture
a tab, or or you trying to get the tab to switch the focus to different windows(widgets)?

This detects the tab...... it's Perl, but it's the only example I have on hand.

#! /usr/bin/perl -w
use strict;
use Gtk2::Gdk::Keysyms;
use Glib qw/TRUE FALSE/;
use Gtk2 -init;

my $window = Gtk2::Window->new ('toplevel');
$window->signal_connect (delete_event => sub { Gtk2->main_quit });
$window->signal_connect('key-press-event' => \&show_key);
	
 	my $label = Gtk2::Label->new();
 	$label->set_markup("<span foreground=\"blue\" size=\"x-large\">Type something on the keyboard!</span>");
	
$window->add ($label);
$window->show_all;
$window->set_position ('center-always');

Gtk2->main;

sub show_key {

my ($widget,$event,$parameter)= @_;

my $key_nr = $event->keyval();

	#run trough the available key names, and get the values of each,
	#compare this with $event->keyval(), when you get a match exit the loop
	foreach my $key  (keys %Gtk2::Gdk::Keysyms){
	
		my $key_compare = $Gtk2::Gdk::Keysyms{$key};
		
		if($key_compare == $key_nr){
		#print ("You typed $key \n");
		$label->set_markup("<span foreground=\"blue\" size=\"x-large\">You typed a</span><span foreground=\"red\" size=\"30000\"><i><tt> $key</tt></i></span><span foreground=\"blue\" size=\"x-large\"> which has a numeric value of </span><span foreground=\"red\" size=\"30000\"><i><tt> $key_nr!</tt></i></span>");
		$widget->set_title("key pressed: $key -> numeric value: $key_nr");
		last;
		}
	}
	#good practice to let the event propagate, should we need it somewhere else
	return FALSE;
}
__END__


zentara

-- 
I'm not really a human, but I play one on earth.
http://www.zentara.net/~zentaran/My_Petition_to_the_Great_Cosmic_Conciousness.html 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]