Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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"; } }



In reply to Gtk2-Perl: How to catch shift-clicking of a button? by Bloehdian

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (5)
    As of 2018-01-20 11:27 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (226 votes). Check out past polls.