赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 2 |
经验 | 0 |
最后登录 | 2023-7-30 |
在线时间 | 10 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 170
- 在线时间
- 10 小时
- 注册时间
- 2020-2-16
- 帖子
- 9
|
得用win32api的user32的GetGetKeyState来获取键盘按键情况
参考一下我以前做的,包含双击的判断,wasd的值我没用到需要自己去查,然后在其他类里把原本的判断输入情况的部分Input.trigger?(Input::B)这种改成对应的方法
- #==============================================================================
- # ** Scene_Base
- #------------------------------------------------------------------------------
- # 這個類是遊戲中所有場景畫面所共同繼承的父類。
- #==============================================================================
- class Scene_Base
- MOUSEEVENT_LEFTDOWN=2
- MOUSEEVENT_LEFTUP=4
- MOUSEEVENT_RIGHTDOWN=0x0008
- MOUSEEVENT_RIGHTUP=0x0010
- M_LEFT=0x00
- M_RIGHT=0x01
- K_LEFT=0x25
- K_UP=0x26
- K_RIGHT=0x27
- K_DOWN=0x28
- K_C=0x43
- K_X=0x58
- K_Z=0x5A
- #--------------------------------------------------------------------------
- # * 主程式
- #--------------------------------------------------------------------------
- def main
- start # 程式開始
- perform_transition # 執行畫面過渡顯示漸變
- post_start # 程式開始後的處理
- Input.update # 更新指令輸入資訊
- loop do
- Graphics.update # 更新螢幕內容
- Input.update # 更新指令輸入資訊
- update # 更新幀
- break if $scene != self # 當畫面切換的時候,中止一切迴圈處理
- end
- Graphics.update
- pre_terminate # 程式終止前的處理
- Graphics.freeze # 執行畫面過渡顯示漸變
- terminate # 程式終止
- end
- #--------------------------------------------------------------------------
- # * 程式開始
- #--------------------------------------------------------------------------
- def start
- @GetCursePos=Win32API.new("user32","GetCursorPos",['p'],'V')
- @GetWindowRect=Win32API.new("user32","GetWindowRect",['i','p'],'V')
- @GetGetKeyState=Win32API.new("user32","GetKeyState",'I','I')
- @GetClientRect=Win32API.new("user32","GetClientRect",['i','p'],'i')
- @GcreenToClient=Win32API.new("user32","ScreenToClient",['i','p'],'V')
- @GetActiveWindow = Win32API.new("user32", "GetActiveWindow", [], 'L')
- @lastmouse=Array.new(500,-1)
- @doubletimer=Array.new(500,-1)
- end
- #--------------------------------------------------------------------------
- # * 執行畫面過渡顯示漸變
- #--------------------------------------------------------------------------
- def perform_transition
- Graphics.transition(10)
- end
- #--------------------------------------------------------------------------
- # * 程式開始後的處理
- #--------------------------------------------------------------------------
- def post_start
- end
- #--------------------------------------------------------------------------
- # * 更新幀
- #--------------------------------------------------------------------------
- def update
- i=0
- while i<500
- @doubletimer[i]-=1 if @doubletimer[i]>0
- i+=1
- end
- end
- #--------------------------------------------------------------------------
- # * 鼠标x
- #--------------------------------------------------------------------------
- def getmousex
- point="\0"*8
- [email protected]()
- @GetCursePos.call(point)
- @GcreenToClient.call(window,point)
- x,y=point.unpack("LL")
- return x
- end
- #--------------------------------------------------------------------------
- # * 鼠标y
- #--------------------------------------------------------------------------
- def getmousey
- point="\0"*8
- [email protected]()
- @GetCursePos.call(point)
- @GcreenToClient.call(window,point)
- x,y=point.unpack("LL")
- return y
- end
- #--------------------------------------------------------------------------
- # * 键按下一次
- #--------------------------------------------------------------------------
- def key_click?(keyid,second=false)#参数是按键id和是否要求是双击的第二击
- kd=false
- if @GetGetKeyState.call(keyid)==65408 or @GetGetKeyState.call(keyid)==65409 or @GetGetKeyState.call(keyid)==-127 or @GetGetKeyState.call(keyid)==-128
- if @GetGetKeyState.call(keyid)!=@lastmouse[keyid]
- kd=true
- @lastmouse[keyid][email protected](keyid)
- if second==false
- else
- kd=false
- if @doubletimer[keyid]>0
- kd=true
- @doubletimer[keyid]=0
- end
- end
- @doubletimer[keyid]=10
- end
- end
- return kd
- end
- #--------------------------------------------------------------------------
- # * 键抬起一次
- #--------------------------------------------------------------------------
- def key_unclick?(keyid)
- kd=false
- if @GetGetKeyState.call(keyid)==1 or @GetGetKeyState.call(keyid)==0
- if @GetGetKeyState.call(keyid)!=@lastmouse[keyid]
- kd=true
- @lastmouse[keyid][email protected](keyid)
- end
- end
- return kd
- end
- #--------------------------------------------------------------------------
- # * 键按下持续
- #--------------------------------------------------------------------------
- def key_down?(keyid)
- kd=false
- if @GetGetKeyState.call(keyid)==65408 or @GetGetKeyState.call(keyid)==65409 or @GetGetKeyState.call(keyid)==-127 or @GetGetKeyState.call(keyid)==-128
- kd=true
- end
- return kd
- end
- #--------------------------------------------------------------------------
- # * 键抬起持续
- #--------------------------------------------------------------------------
- def key_up?(keyid)
- kd=false
- if @GetGetKeyState.call(keyid)==0 or @GetGetKeyState.call(keyid)==1
- kd=true
- end
- return kd
- end
- #--------------------------------------------------------------------------
- # * 鼠标左键单击
- #--------------------------------------------------------------------------
- def mleft_down?
- return key_click?(0x01)
- end
- #--------------------------------------------------------------------------
- # * 鼠标右键单击
- #--------------------------------------------------------------------------
- def mright_down?
- return key_click?(0x02)
- end
- #--------------------------------------------------------------------------
- # * 程式終止前的處理
- #--------------------------------------------------------------------------
- def pre_terminate
- end
- #--------------------------------------------------------------------------
- # * 程式終止
- #--------------------------------------------------------------------------
- def terminate
- end
- #--------------------------------------------------------------------------
- # * 為生成其他場景畫面的背景而截圖
- #--------------------------------------------------------------------------
- def snapshot_for_background
- $game_temp.background_bitmap.dispose
- $game_temp.background_bitmap = Graphics.snap_to_bitmap
- $game_temp.background_bitmap.blur
- end
- #--------------------------------------------------------------------------
- # * 創建選單畫面背景
- #--------------------------------------------------------------------------
- def create_menu_background
- @menuback_sprite = Sprite.new
- @menuback_sprite.bitmap = $game_temp.background_bitmap
- @menuback_sprite.color.set(16, 16, 16, 128)
- update_menu_background
- end
- #--------------------------------------------------------------------------
- # * 清除選單畫面背景
- #--------------------------------------------------------------------------
- def dispose_menu_background
- @menuback_sprite.dispose
- end
- #--------------------------------------------------------------------------
- # * 更新選單畫面背景顯示內容
- #--------------------------------------------------------------------------
- def update_menu_background
- end
- end
复制代码
|
|