Ncurses 函数
在线手册:中文  英文

ncurses_getmouse

(PHP 4 >= 4.2.0, PHP 5 < 5.3.0, PECL ncurses >= 1.0.0)

ncurses_getmouseReads mouse event

说明

bool ncurses_getmouse ( array &$mevent )
Warning

此函数是实验性的。此函数的表象,包括名称及其相关文档都可能在未来的 PHP 发布版本中未通知就被修改。使用本函数风险自担 。

ncurses_getmouse() reads mouse event out of queue.

参数

mevent

Event options will be delivered in this parameter which has to be an array, passed by reference (see example below).

On success an associative array with following keys will be delivered:

  • "id" : Id to distinguish multiple devices

  • "x" : screen relative x-position in character cells

  • "y" : screen relative y-position in character cells

  • "z" : currently not supported

  • "mmask" : Mouse action

返回值

Returns FALSE if a mouse event is actually visible in the given window, otherwise returns TRUE.

范例

Example #1 ncurses_getmouse() example

<?php
switch (ncurses_getch()){
  case 
NCURSES_KEY_MOUSE:
    if (!
ncurses_getmouse($mevent)){
      if (
$mevent["mmask"] & NCURSES_MOUSE_BUTTON1_PRESSED){
        
$mouse_x $mevent["x"]; // Save mouse position
        
$mouse_y $mevent["y"];
      }
    }
  break;

  default:
    
/* .... */
}
?>

参见


Ncurses 函数
在线手册:中文  英文

用户评论:

m dot quinton at gmail dot com (2005-09-26 04:05:50)

a working example with mouse, 3 windows  (need to be completed, but it works) ...

<?php

error_reporting
(E_ALL);

function 
win($w$h$x$y$txt){
    
// now lets create a small window
    
$win ncurses_newwin($w$h$x$y);
    
// border our small window.
    
ncurses_wborder($win,0,00,00,00,0);
    
# ncurses_wrefresh($win);// paint both windows
    
ncurses_refresh();// paint both windows

    // move into the small window and write a string
    
ncurses_mvwaddstr($win01$txt ");
    
ncurses_mvwaddstr($win11"($w$h$x$y)");

    
// show our handiwork and refresh our small window
    
ncurses_wrefresh($win);

    return 
$win;
}

// Initialie ncurses
$ncurse ncurses_init();
// A full screen window

$win0 win(0000'win0');
$win1 win(1030725'win1');
$win2 win(10302025'win2');
$info win(152022'info');

// Draw everything so far
// ncurses_refresh();

$newmask NCURSES_BUTTON1_CLICKED NCURSES_BUTTON1_RELEASED;
# $newmask = NCURSES_ALL_MOUSE_EVENTS;

$mask ncurses_mousemask($newmask, &$oldmask);
$events = array();

while(
1){

    
ncurses_wmove($info1,1);
    
$ch ncurses_getch();

    
ncurses_wclear($info);
    
ncurses_refresh();// paint both windows
    
ncurses_wborder($info,0,00,00,00,0);
    
ncurses_refresh();// paint both windows
    
ncurses_mvwaddstr($win01" info ");
    
ncurses_refresh();// paint both windows

    
switch($ch){

    case 
NCURSES_KEY_MOUSE:

        if(
ncurses_getmouse($mevent)){
            
$events[] = $mevent;

            
ncurses_mvwaddstr($info21" mouse event   ");
            
ncurses_mvwaddstr($info31" ({$mevent['x']}/{$mevent['y']}) ");
            
ncurses_mvwaddstr($info41" ({$mevent['mmask']}) ");

            
ncurses_wrefresh($info);
        }
        break;

    case 
chr('q'):
        break 
2;

    default:

        if(
$ch 0x40)
            
$txt chr($ch) . $ch ";
        else
            
$txt '.' $ch";

        
ncurses_mvwaddstr($info11$txt   ");
        
ncurses_wrefresh($info);

    }

    if(
chr($ch) == 'q')
        break;
}

ncurses_end();// clean up our screen

print_r($events);

?>

易百教程