Win32 API 日本語リファレンス
ホームUI.Input.KeyboardAndMouse › MOUSEINPUT

MOUSEINPUT

構造体
サイズx64: 32 バイト / x86: 24 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
dxINT4+0+0マウスの相対移動量または絶対座標のX成分。dwFlagsのMOUSEEVENTF_ABSOLUTEで意味が変わる。
dyINT4+4+4マウスの相対移動量または絶対座標のY成分。dwFlagsのMOUSEEVENTF_ABSOLUTEで意味が変わる。
mouseDataDWORD4+8+8ホイール回転量やXボタン情報。フラグに応じた追加データを保持する。
dwFlagsMOUSE_EVENT_FLAGS4+12+12マウス操作の種類を示すフラグの組み合わせ。移動・ボタン押下・ホイール等を指定する。
timeDWORD4+16+16イベントのタイムスタンプ(ミリ秒)。0でシステムが自動付与する。
dwExtraInfoUINT_PTR8/4+24+20アプリケーション定義の追加情報。GetMessageExtraInfoで取得できる値。

各言語での定義

#include <windows.h>

// MOUSEINPUT  (x64 32 / x86 24 バイト)
typedef struct MOUSEINPUT {
    INT dx;
    INT dy;
    DWORD mouseData;
    MOUSE_EVENT_FLAGS dwFlags;
    DWORD time;
    UINT_PTR dwExtraInfo;
} MOUSEINPUT;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MOUSEINPUT
{
    public int dx;
    public int dy;
    public uint mouseData;
    public uint dwFlags;
    public uint time;
    public UIntPtr dwExtraInfo;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure MOUSEINPUT
    Public dx As Integer
    Public dy As Integer
    Public mouseData As UInteger
    Public dwFlags As UInteger
    Public time As UInteger
    Public dwExtraInfo As UIntPtr
End Structure
import ctypes
from ctypes import wintypes

class MOUSEINPUT(ctypes.Structure):
    _fields_ = [
        ("dx", ctypes.c_int),
        ("dy", ctypes.c_int),
        ("mouseData", wintypes.DWORD),
        ("dwFlags", wintypes.DWORD),
        ("time", wintypes.DWORD),
        ("dwExtraInfo", ctypes.c_size_t),
    ]
#[repr(C)]
pub struct MOUSEINPUT {
    pub dx: i32,
    pub dy: i32,
    pub mouseData: u32,
    pub dwFlags: u32,
    pub time: u32,
    pub dwExtraInfo: usize,
}
import "golang.org/x/sys/windows"

type MOUSEINPUT struct {
	dx int32
	dy int32
	mouseData uint32
	dwFlags uint32
	time uint32
	dwExtraInfo uintptr
}
type
  MOUSEINPUT = record
    dx: Integer;
    dy: Integer;
    mouseData: DWORD;
    dwFlags: DWORD;
    time: DWORD;
    dwExtraInfo: NativeUInt;
  end;
const MOUSEINPUT = extern struct {
    dx: i32,
    dy: i32,
    mouseData: u32,
    dwFlags: u32,
    time: u32,
    dwExtraInfo: usize,
};
type
  MOUSEINPUT {.bycopy.} = object
    dx: int32
    dy: int32
    mouseData: uint32
    dwFlags: uint32
    time: uint32
    dwExtraInfo: uint
struct MOUSEINPUT
{
    int dx;
    int dy;
    uint mouseData;
    uint dwFlags;
    uint time;
    size_t dwExtraInfo;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; MOUSEINPUT サイズ: 24 バイト(x86)
dim st, 6    ; 4byte整数×6(構造体サイズ 24 / 4 切り上げ)
; dx : INT (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; dy : INT (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; mouseData : DWORD (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; dwFlags : MOUSE_EVENT_FLAGS (+12, 4byte)  st.3 = 値  /  値 = st.3   (lpoke/lpeek も可)
; time : DWORD (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; dwExtraInfo : UINT_PTR (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; MOUSEINPUT サイズ: 32 バイト(x64)
dim st, 8    ; 4byte整数×8(構造体サイズ 32 / 4 切り上げ)
; dx : INT (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; dy : INT (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; mouseData : DWORD (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; dwFlags : MOUSE_EVENT_FLAGS (+12, 4byte)  st.3 = 値  /  値 = st.3   (lpoke/lpeek も可)
; time : DWORD (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; dwExtraInfo : UINT_PTR (+24, 8byte)  qpoke st,24,値 / qpeek(st,24)  ※IronHSPのみ。3.7/3.8は lpoke st,24,下位 : lpoke st,28,上位
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global MOUSEINPUT
    #field int dx
    #field int dy
    #field int mouseData
    #field int dwFlags
    #field int time
    #field intptr dwExtraInfo
#endstruct

stdim st, MOUSEINPUT        ; NSTRUCT 変数を確保
st->dx = 100
mes "dx=" + st->dx