使用Win32::Console中的Input
方法时,什么会造成鼠标拖动?
use Win32::Console qw(STD_INPUT_HANDLE ENABLE_MOUSE_INPUT);
my $con_in = Win32::Console->new(STD_INPUT_HANDLE);
$con_in->Mode(ENABLE_MOUSE_INPUT);
sub getch {
my ( $arg ) = @_;
my @event = $con_in->Input();
my $event_type = shift( @event );
if ( defined $event_type and $event_type == 2 ) {
my( $x, $x, $button_state, $control_key, $event_flags ) = @event;
my $button_drag = ?;
return handle_mouse( $x, $y, $button_state, $button_drag, $arg );
}
}
Linux上的getch
如下所示:
sub getch {
my ( $arg ) = @_;
my $c = ReadKey 0;
if ( $c eq "\e" ) {
my $c = ReadKey 0.10;
# ...
if ( $c eq '[' ) {
my $c = ReadKey 0;
# ...
if ( $c eq 'M' ) {
# On button press, xterm sends CSI M C b C x C y (6 characters).
my $event_type = ord( ReadKey 0 ) - 32;
my $x = ord( ReadKey 0 ) - 32;
my $y = ord( ReadKey 0 ) - 32;
my $button_drag = ( $event_type & 0x20 ) >> 5;
my $button_pressed;
my $low3bits = $event_type & 0x03;
if ( $low3bits == 0x03 ) {
$button_pressed = 0;
} else {
if ( $event_type & 0x40 ) {
$button_pressed = $low3bits + 4;
} else {
$button_pressed = $low3bits + 1;
}
}
return handle_mouse( $x, $y, $button_pressed, $button_drag, $arg );
}
# ...
}
}
}
答案 0 :(得分:0)
我找到了一些东西,但我不确定它是否正确。
use Win32::Console qw(STD_INPUT_HANDLE ENABLE_MOUSE_INPUT);
my $con_in = Win32::Console->new(STD_INPUT_HANDLE);
$con_in->Mode(ENABLE_MOUSE_INPUT);
sub getch {
my ( $arg ) = @_;
my @event = $con_in->Input();
my $event_type = shift( @event );
if ( defined $event_type and $event_type == 2 ) {
my( $x, $x, $button_state, $control_key, $event_flags ) = @event;
my $button_drag = 0;
# MOUSEEVENTF_MOVE => 0x0001
$button_drag = 1 if $event_flags & MOUSEEVENTF_MOVE;
return handle_mouse( $x, $y, $button_state, $button_drag, $arg );
}
}