このマウス処理命令は、現在のマウス操作状態を調べるために使用できます。またマウスカーソルの外観を変更することもできます。
ディスプレイモードが設定された時、マウスイベントからの情報を受け取るためのイベントキューが開始されます。マウスボタンが押された時にはpygame.MOUSEBUTTONDOWNイベントが発生し、マウスボタンが離された時にはpygame.MOUSEBUTTONUPイベントが発生します。これらのイベントには、どのボタンが押されたかを表すボタン情報も含まれています。マウスホイールをスクロールするのはボタンが押されたと判断されるので、pygame.MOUSEBUTTONDOWNイベントが発生します。マウスホイールを上にスクロールした場合はMOUSEBUTTONDOWNイベントのボタン情報には4が設定され、マウスホイールを下にスクロールした場合のボタン情報には5が設定されます。マウスを動かす際には常時pygame.MOUSEMOTIONイベントが発生します。マウスが動くと、その移動情報は細かく精密に分けられてイベントが発生するので、マウスが動く度に大量のマウス動作イベントがキューに取得されます。マウス動作イベントがイベントキューから適切に削除されないと、イベントビューが満杯になってしまいます。
マウスカーソルが非表示状態でなおかつウィンドウがパソコンの入力処理を占有している場合、マウスはバーチャルインプットモードに切り替わります。このモードで、マウスはウィンドウの枠内に制限されることなく動くことができます。カーソル非表示やウィンドウの入力処理占有についての設定は、pygame.mouse.set_visible命令とpygame.event.set_grab命令を参照してください。
The mouse functions can be used to get the current state of the mouse device. These functions can also alter the system cursor for the mouse.
When the display mode is set, the event queue will start receiving mouse events. The mouse buttons generate pygame.MOUSEBUTTONDOWN and pygame.MOUSEBUTTONUP events when they are pressed and released. These events contain a button attribute representing which button was pressed. The mouse wheel will generate pygame.MOUSEBUTTONDOWN events when rolled. The button will be set to 4 when the wheel is rolled up, and to button 5 when the wheel is rolled down. Anytime the mouse is moved it generates a pygame.MOUSEMOTION event. The mouse movement is broken into small and accurate motion events. As the mouse is moving many motion events will be placed on the queue. Mouse motion events that are not properly cleaned from the event queue are the primary reason the event queue fills up.
If the mouse cursor is hidden, and input is grabbed to the current display the mouse will enter a virtual input mode, where the relative movements of the mouse will never be stopped by the borders of the screen. See the functions pygame.mouse.set_visible - hide or show the mouse cursor and pygame.event.set_grab - control the sharing of input devices with other applications to get this configured.
全てのマウスボタンの入力状態を表すboolean型の配列を戻り値として返します。戻り値がtrueの場合は、命令実行時にそのボタンが押されていたということです。
マウスの全ての動作を取得する場合には、この命令を使うのではなくpygame.event.wait()やpygame.event.get()命令を使用して得られたイベントの状態をMOUSEBUTTONDOWN、 MOUSEBUTTONUP、MOUSEMOTION定数を使って確認するほうがよいでしょう。
X Window System環境おいて、マウスの真ん中ボタンのクリック処理を擬似的に実行することができるXServerもあります。左クリック(button1)と右クリック(buttons3)を同時にクリックすると、真ん中ボタン(button2)のクリックイベントを発生させることができます。
この命令を実行する際には、事前に pygame.event.get命令を実行するようにしてください。実行しておかないとこの命令は機能しない仕様となっています。
Returns a sequence of booleans representing the state of all the mouse buttons. A true value means the mouse is currently being pressed at the time of the call.
Note, to get all of the mouse events it is better to use either
pygame.event.wait() or pygame.event.get() and check all of those events
to see if they are MOUSEBUTTONDOWN, MOUSEBUTTONUP, or MOUSEMOTION.
Note, that on X11 some XServers use middle button emulation. When you click both buttons 1 and 3 at the same time a 2 button event can be emitted.
Note, remember to call pygame.event.get - get events from the queue before this function. Otherwise it will not work.
マウスカーソルのX位置とY位置の値を戻り値として返します。ここで取得できる位置情報は、ディスプレイの左上を基準とした相対位置です。マウスカーソルはウィンドウの枠外にも移動させることはできますが、カーソルの位置情報についてはウィンドウの枠内に制限された値となります。
Returns the X and Y position of the mouse cursor. The position is relative the the top-left corner of the display. The cursor position can be located outside of the display window, but is always constrained to the screen.
前回この命令が実行された時のマウス位置から、マウスの移動したX距離とY距離を戻り値として返します。マウスの移動する距離はウィンドウの枠内に制限されますが、この制限を回避する方法についてはマウスはバーチャルインプットモードを参照してください。バーチャルインプットモードについてはこのページの最初の項目に詳細が記載されています。
Returns the amount of movement in X and Y since the previous call to this function. The relative movement of the mouse cursor is constrained to the edges of the screen, but see the virtual input mouse mode for a way around this. Virtual input mode is described at the top of the page.
引数として設定した位置にマウスの位置を移動させます。マウスが表示状態の場合はカーソルが設定した位置までジャンプします。この命令でマウスが移動するとpygaqme.MOUSEMOTIONイベントが発生します。
Set the current mouse position to arguments given. If the mouse cursor is visible it will jump to the new coordinates. Moving the mouse will generate a new pygaqme.MOUSEMOTION event.
bool引数にtrueを設定した場合、マウスカーソルは表示状態になります。この命令で設定を変更する前のカーソル表示状態が、戻り値として返されます。
If the bool argument is true, the mouse cursor will be visible. This will return the previous visible state of the cursor.
pagameがマウスからの入力イベントを受け取れる状態であればtrueが戻り値として返されます。 (この状態のことをWinodws界隈の専門用語では「アクティブ状態になっている」、もしくは「フォーカスを得ている」と言います)。
この命令はウィンドウ表示での処理を行う際に役に立ちます。一方フルスクリーン表示の場合はプログラムがマウス入力処理を占有しているため、この命令では常に戻り値がtrueとなるのであまり使う意味がありません。
Note:Windows環境においては、ウィンドウがマウス入力処理を受け取れる状態の場合は、同時にキーボードの入力処理も受け取れる状態になります。しかしX-Windows環境では、ウィンドウがマウス入力処理イベントとキーボードの入力処理イベントを別々に持つことができます。pygame.mouse.get_focusedはpygameのウィンドウがマウスイベントを受け取れるかどうかを示します。
Returns true when pygame is receiving mouse input events (or, in windowing terminology, is "active" or has the "focus").
This method is most useful when working in a window. By contrast, in full-screen mode, this method always returns true.
Note: under MS Windows, the window that has the mouse focus also has the keyboard focus. But under X-Windows, one window can receive mouse events and another receive keyboard events. pygame.mouse.get_focused - check if the display is receiving mouse input indicates whether the pygame window receives mouse events.
マウスカーソルが表示状態の場合、カーソルはビットマスクの配列を使用した白黒のビットマップ画像で表示されます。size引数にはカーソルの横幅と縦幅のタプル値を設定します。 Hotspot引数にはカーソル画像内のクリック対象となる位置を設定します。 xormasks引数にはカーソルのxorデータマスクを設定します。最後に、andmasks引数にはカーソルのビットマスクデータを設定します。
カーソルの横幅は8の倍数でなければならず、またマスクとして設定する二次元配列のサイズは、size引数に設定した横幅と縦幅の各数値と一致していなければなりません。そうしないと例外が発生してしまいます。
システムカーソルを描写するための既定のマスクを作成したり、編集したりする方法についてはpygame.cursorモジュールを参照してください。
When the mouse cursor is visible, it will be displayed as a black and white bitmap using the given bitmask arrays. The size is a sequence containing the cursor width and height. Hotspot is a sequence containing the cursor hotspot position. xormasks is a sequence of bytes containing the cursor xor data masks. Lastly is andmasks, a sequence of bytes containting the cursor bitmask data.
Width must be a multiple of 8, and the mask arrays must be the correct size for the given width and height. Otherwise an exception is raised.
See the pygame.cursor module for help creating default and custom masks for the system cursor.
マウスカーソルのシステム情報を取得します。pygame.mouse.set_cursor命令で設定した引数と同じ値が戻り値として返されます。
Get the information about the mouse system cursor. The return value is the same data as the arguments passed into pygame.mouse.set_cursor - set the image for the system mouse cursor.