BlitzMax/模組/使用者輸入/輪詢輸入
輪詢輸入模組提供了一種簡單的方法來檢測鍵盤和滑鼠輸入。
此模組中的函式僅在程式在 圖形 模式下執行時可用。在處理 GUI 應用程式時,應使用 事件。
函式 AppSuspended()
描述: 獲取應用程式掛起狀態
返回值: 如果應用程式當前處於掛起狀態,則為 True。
函式 AppTerminate()
描述: 返回應用程式終止狀態
返回值: 如果使用者已請求終止應用程式,則為 True
示例:
Graphics 640,480,0 While Not AppTerminate() Or Not Confirm( "Terminate?" ) Cls DrawText MouseX()+","+MouseY(),0,0 Flip Wend
函式 KeyHit( key )
描述: 檢查按鍵是否被按下
返回值: key 被按下的次數。
資訊: 返回值表示自上次呼叫具有相同 key 的 KeyHit 以來,key 被按下的次數。
有關有效按鍵程式碼的列表,請參見 按鍵程式碼 模組。
示例:
' keyhit.bmx ' the following code draws a circle every time the ' program detects the spacebar has been pressed ' and exits when it detects the ESCAPE key has ' been pressed graphics 640,480 while not keyhit(KEY_ESCAPE) cls if keyhit(KEY_SPACE) drawoval 0,0,640,480 flip wend
函式 KeyDown( key )
描述: 檢查按鍵狀態
返回值: 如果 key 當前處於按下狀態,則為 True
資訊: 有關有效按鍵程式碼的列表,請參見 按鍵程式碼 模組。
示例:
' keydown.bmx ' the following code draws a circle if the ' program detects the spacebar is pressed ' and exits when it detects the ESCAPE key has ' been pressed Graphics 640,480 While Not KeyHit(KEY_ESCAPE) Cls If KeyDown(KEY_SPACE) DrawOval 0,0,640,480 Flip Wend
函式 GetChar()
描述: 獲取下一個字元
返回值: 下一個字元的字元程式碼。
資訊: 當用戶在鍵盤上按下按鍵時,BlitzMax 會將這些按鍵的字元程式碼記錄到一個內部的“字元佇列”中。
GetChar 從該佇列中刪除下一個字元程式碼並將其返回給應用程式。
如果字元佇列為空,則返回 0。
函式 FlushKeys()
描述: 清除按鍵狀態和字元佇列。
資訊: FlushKeys 將所有按鍵的狀態重置為“關閉”,並重置 GetChar 使用的字元佇列。
函式 MouseX()
描述: 獲取滑鼠 x 座標
返回值: 滑鼠 x 軸座標
資訊: 返回值相對於螢幕的左側。
示例:
' mousex.bmx ' the following tracks the position of the mouse graphics 640,480 while not keyhit(KEY_ESCAPE) cls drawoval mousex()-10,mousey()-10,20,20 flip wend
函式 MouseY()
描述: 獲取滑鼠 y 座標
返回值: 滑鼠 y 軸座標
資訊: 返回值相對於螢幕的頂部。
示例:
' mousey.bmx ' the following tracks the position of the mouse graphics 640,480 while not keyhit(KEY_ESCAPE) cls drawrect mousex()-10,mousey()-10,20,20 flip wend
函式 MouseZ()
描述: 獲取滑鼠滾輪
返回值: 滑鼠滾輪值
資訊: 當滑鼠滾輪“遠離”使用者滾動時,滑鼠滾輪值會增加;當滑鼠滾輪“朝向”使用者滾動時,滑鼠滾輪值會減少。
示例:
' mousez.bmx ' prints mousez() the mousewheel position Graphics 640,480 While Not keyhit(KEY_ESCAPE) cls drawtext "MouseZ()="+MouseZ(),0,0 flip Wend
函式 MouseXSpeed()
描述: 獲取滑鼠 x 速度
返回值: 滑鼠 x 速度
函式 MouseYSpeed()
描述: 獲取滑鼠 y 速度
返回值: 滑鼠 y 速度
函式 MouseZSpeed()
描述: 獲取滑鼠 z 速度
返回值: 滑鼠 z 速度
函式 FlushMouse()
描述: 清除滑鼠按鈕狀態
資訊: FlushMouse 將所有滑鼠按鈕的狀態重置為“關閉”。
函式 MouseHit( button )
描述: 檢查滑鼠按鈕是否被點選
返回值: button 被點選的次數。
資訊: 返回值表示自上次呼叫具有相同 button 的 MouseHit 以來,button 被點選的次數。
button 應為 1 代表左鍵,2 代表右鍵,或 3 代表中鍵。
示例:
' mousehit.bmx graphics 640,480 while not keyhit(KEY_ESCAPE) cls if mousehit(1) drawrect 0,0,200,200 if mousehit(2) drawrect 200,0,200,200 if mousehit(3) drawrect 400,0,200,200 flip wend
函式 MouseDown( button )
描述: 檢查滑鼠按鈕是否處於按下狀態
返回值: 如果 button 當前處於按下狀態,則為 True
資訊: 按鈕 應為 1 代表左鍵,2 代表右鍵或 3 代表中鍵。
示例:
' mousedown.bmx graphics 640,480 while not keyhit(KEY_ESCAPE) cls if mousedown(1) drawrect 0,0,200,200 if mousedown(2) drawrect 200,0,200,200 if mousedown(3) drawrect 400,0,200,200 flip wend
Function WaitKey()
描述: 等待按鍵按下
返回值: 按下按鍵的鍵碼
資訊: WaitKey 會暫停程式執行,直到有按鍵被按下。然後,該按鍵的鍵碼將被返回到應用程式。
有關有效鍵碼列表,請參閱鍵碼 模組。
Function WaitChar()
描述: 等待按鍵按下
返回值: 按下按鍵的字元程式碼
資訊: WaitChar 會暫停程式執行,直到從 GetChar 獲得字元。然後,該字元將被返回到應用程式。
Function WaitMouse()
描述: 等待滑鼠按鈕點選
返回值: 點選的按鈕
資訊: WaitMouse 會暫停程式執行,直到滑鼠按鈕被點選。
WaitMouse 如果左鍵被點選,則返回 1;如果右鍵被點選,則返回 2;如果中鍵被點選,則返回 3。