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

Hi,

There is this useful yet annoying feature on windows command prompt called quick edit mode. Useful because it lets a user cut and paste off the command prompt. Annoying because it causes a running process to hang in select mode (that is an unsuspecting ignorant user clicking once in the command prompt window by mistake). This feature is on by default in our working environment. I am looking for a way to turn this off while a user runs my perl scripts, to prevent him from hanging the running script. One of the ways suggested to me by someone here was to use a sparsely documented win32 perl module called Win32::Console. I have found very few examples on the use of this module. Below is a snippet of the perl code that I am trying to turn quick edit mode off with:

$myConsole = Win32::Console->new(STD_INPUT_HANDLE); $myConsole->Title("Title 1"); # this works my $mode = $myConsole->Mode(); # Get the current console mode $mode = $mode & 0xFFBF; $myConsole->Mode($mode) || die "error setting console mode to $mode "; sleep 10;


The above code fails for me with the die message. Any further help would be greatly appreciated. I am also open to any other ideas which might bypass using win32::console module.

Thanks,
Waris

Replies are listed 'Best First'.
Re: win32::console question
by bart (Canon) on Jan 08, 2003 at 10:00 UTC
    First of all, I found these docs on CPAN, so I wouldn't call this module underdocumented.

    Second: why aren't you using the constants provided? The above docs mention which modes are legal for Mode. I tried to figure out exactly which one you're resetting, but bitwise OR of all constants listed gave me a value of 0x1F. Clearly, whichever bit you are resetting, it's not in this list.

    I followed the link in the docs to Microsoft's reference page, but it's a dead end. A bit of poking around, and I came up with this link: Console Modes, explaining all available modes, both under "high-level" and "low-level" modes.

    Anyway, once you figure out which bit to reset, you can do it using the constant, like this:

    $mode &= ~CONSTANT;

    p.s. My first guess would be that you need to use ENABLE_MOUSE_INPUT, but don't pin me down on it. It's not even clear to me what problem you are describing.

Re: win32::console question
by Mr. Muskrat (Canon) on Jan 08, 2003 at 00:06 UTC

    I'm using Windows 98 with AS Perl 5.6.1 build 633.

    Your snippet of code runs provided I add use Win32::Console; to the beginning. The title gets changed and then it sleeps without dying. However, "quick edit" mode is not disabled. Are you sure that you have the right hex code? Also, what OS and Perl are you using?

Re: win32::console question
by Mr. Muskrat (Canon) on Jan 08, 2003 at 14:13 UTC

    A google for disable "quick edit" results in quite a few entries. If you are using Windows NT/2000/XP, they say that you need to edit the registry and set HKEY_CURRENT_USER\Console\"QuickEdit" to "0" to disable or "1" to enable. Might I recommend using Win32::TieRegistry for the task.

    Something like this should work. (I haven't tested it since I have Windows 98 on this machine.)

    #!perl -w use strict; use Win32::TieRegistry; my $key = new Win32::TieRegistry "CUser/Console/", { Delimiter => "/" }; $key->{"//QuickEdit"} = [ "0x0000", "REG_DWORD" ];