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

I've got a small piece of code.
use Win32::GuiTest qw(:ALL); until ($is_pressed){ $is_pressed = IsKeyPressed("ESC"); }
This particular example works, but when I change
$is_pressed = IsKeyPressed("ESC");
to any value other then ESC seems NOT to work for me. I thought this was going to be easy, but it's turning into a headache.

Replies are listed 'Best First'.
Re: Win32::GuiTest IsKeyPressed function
by GrandFather (Saint) on Apr 28, 2006 at 19:13 UTC

    Which specific keys are you having trouble with? The API function GetAsyncKeyState actually accepts virtual key codes so either the wrapper around it is doing some translation, or you need to know what the codes are. In particular, if you want to detect the state of a letter key, you must provide it upper case - 'A' rather than 'a'.


    DWIM is Perl's answer to Gödel
      The wrapper around it *is* doing translation! Here is the table from guitest.xs: Update: Hmmm. This should have shown up as a reply to Grandfather's post. Curious...

        Is there a reason that these codes are not documented in the module documentation?

        Is there a reason that the MicroSoft codes are not used?

        Is there a reason that the symbolic names are not the same as the MicroSoft symbolic names?

        Why do keys such as 'A' not work?

        Would it not have been simpler to use and document (and possibly also to write the code) to pass an integer value straight through, convert letters to the uppercase equivelent ordinal code and possibly do some symbolic conversion as icing?

        Why is the sample code mentioned in the documentation not provided?


        DWIM is Perl's answer to Gödel

      Try 'F1'. The special keys work in older versions of Win32::GuiTest.
      The code to allow IsKeyPressed to understand a parameter of 'A' was added in version 1.50.2-ad. You probably are running 1.3. Try this to see:

      perl -MWin32::GuiTest -wle print($Win32::GuiTest::VERSION)
      See my reply to Grandfather, above, for the correct table of special keys that work with 1.3.

      I have tried the virtual key codes, I have tried single quotes, I have tried double quotes (I even tried no quotes).
      IsKeyPressed("A"); IsKeyPressed('A'); IsKeyPressed("a"); IsKeyPressed('A'); IsKeyPressed("A"); IsKeyPressed("41"); IsKeyPressed(41); IsKeyPressed("VK_BACK"); #backspace key
      I litterly cannot get any key on the keyboard to work except the ESC key. Is anyone else having this problem with my code? or is it just a configuration issue on my PC?
Re: Win32::GuiTest IsKeyPressed function
by ahmad (Hermit) on Apr 28, 2006 at 18:45 UTC

    Hello ,

    what you need is reading the documentation of the module

    search for module documentation in CPAN.org

      I have the only thing in the documentation on that function is what follows
      IsKeyPressed($key) Wrapper around the GetAsyncKeyState API function. Returns TRUE if the +user presses the specified key. IsKeyPressed("ESC"); IsKeyPressed("A"); IsKeyPressed("DOWN");
      According to it, all of these should work.