http://www.perlmonks.org?node_id=1003488

Bloehdian has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I am trying to detect whether the shift key is pressed when a button is clicked. Since I did not find a complete prescription for what I am trying to do in one of the documents on Gtk2 I have at hand I "collected" information from several different sources. Therefore I am not sure at all whether the approach distilled into the test program is correct.

Currently, even execution of this prog fails due to the following compilation error:

Bareword "GDK_SHIFT_MASK" not allowed while "strict subs" in use

This is allegeable since this constant is not exported by any of the modules of the toolkit (i found it in the description of the C-API of Gtk).

So, my questions are as follows:

1. Apart from the obviously wrong bit mask: is my approach to the problem solution correct?

2. Which bit mask do I have to use to detect whether the the shift key was pressed simultaneously with the mouse click?

Perl: 5.8.8

Glib: 1.260

Gtk2: 1.270

OS: Red Hat 4.1.2-46 (Kernel: 2.6.18-164.el5)

The test program:

#!/usr/bin/perl -w use strict; use diagnostics; use Gtk2 -init; my $mw = Gtk2::Window->new(); $mw->signal_connect( 'delete_event' => sub { Gtk2->main_quit; } ); my $button=Gtk2::Button->new_from_stock( 'gtk-add' ); $button->add_events( 'key-press-mask' ); $button->signal_connect( 'clicked' => sub { my ( $widget, $event ) = @_; action( $widget, $event ) } ); $mw->add( $button ); $mw->show_all; Gtk2->main; sub action { my ( $widget, $event ) = @_; if ( ($event->state() & GDK_SHIFT_MASK) == GDK_SHIFT_MASK ) { print "The shift key was pressed\n"; } else { print "The shift key was NOT pressed\n"; } }

Thx

Bloehdian