pyxen.input

キーボード、マウス、タッチスクリーン、ゲームパッドからのリアルタイム入力にアクセスします。

input = pyxen.input

参照:入力


モジュール

モジュール説明
keyboardキーとテキスト入力
mouse位置、移動、ボタン
touchesマルチタッチ入力
gamepadsコントローラー

ボタンモデル

キーボードキー、マウスボタン、ゲームパッドボタンはすべて同じButtonインターフェースを使用します:

button.down
button.pressed
button.released
button.value
プロパティ意味
down押されている間True
pressed押されたフレームでのみTrue
released離されたフレームでのみTrue
valueアナログ値(0.0 → 1.0)

フレームベースの動作

入力はフレームごとに評価されます。

pressedreleasedは1フレームだけtrueで、その後自動的にリセットされます。

if input.keyboard.space.pressed:
    player.jump()

連続的な動作には:

if input.keyboard.space.down:
    charge_power()

クイックサンプル

キーボード移動

kbd = input.keyboard

if kbd.left.down:
    player.x -= 1

if kbd.right.down:
    player.x += 1

マウスクリック

mouse = input.mouse

if mouse.left.pressed:
    x, y = mouse.pos
    spawn_explosion(x, y)

タッチ入力

for t in input.touches:
    if t.started:
        print("Touch at", t.pos)

ゲームパッドのアナログ移動

pad = input.gamepads[0]

if pad.connected:
    x, y = pad.left_stick
    player.x += x * 2
    player.y += y * 2

読み取り専用の安全性

すべての入力オブジェクトは読み取り専用です。入力の状態はエンジンによって管理されます。