Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

Thx

Bloehdian


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

Title:
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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (5)
    As of 2014-12-27 13:36 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (177 votes), past polls