CWKSC's blog | 博客 (已棄用)

鍵盤、滑鼠輸入

Featured image

只是筆記,搬運自:

MonoGame 笔记 - KeyboardState 键盘输入 - 知乎

MonoGame 笔记 - MouseState 滑鼠输入 - 知乎

▌KeyboardState 鍵盤輸入

KeyboardState kb = Keyboard.GetState();

if (kb.IsKeyDown(Keys.Left)){
    // something here
} else if (kb.IsKeyDown(Keys.Right)){
    // something here
} else if (kb.IsKeyDown(Keys.Up)){
    // something here
} else if (kb.IsKeyDown(Keys.Down)){
    // something here
}

▌MouseState 滑鼠輸入

MouseState ms = Mouse.GetState();
if (ms.LeftButton == ButtonState.Pressed){
    // something here
}

Don’t repeat to loop call (mouse down):

ButtonState lastButtonState = ButtonState.Released;

MouseState ms = Mouse.GetState();
if (ms.LeftButton == ButtonState.Pressed && ms.LeftButton != lastButtonState){
    // something here
}
lastButtonState = ms.LeftButton;

▌Reference

Basic Keyboard Input - RB Whitaker’s Wiki

Mouse Input - RB Whitaker’s Wiki

CWKSC

Author 作者

CWKSC

喜歡編程,會一點點鋼琴,會一點點畫畫,喜歡使用顏文字 About me 關於我

For any comments or discussions on my blog post, you can open an issue here

對於我博客文章的任何評論或討論,可以在這裏開一個 issue

Feel free to give your comments. OW<