赞 | 0 |
VIP | 0 |
好人卡 | 3 |
积分 | 1 |
经验 | 1416 |
最后登录 | 2014-7-14 |
在线时间 | 276 小时 |
Lv1.梦旅人 天才琪露诺
- 梦石
- 0
- 星屑
- 54
- 在线时间
- 276 小时
- 注册时间
- 2013-6-24
- 帖子
- 1741
|
- #-----------------------------------------------------------------------------
- #全键盘脚本 by ULTRA
- #v1.1 \10.8.29
- #使用方法:
- #★INP.press?(INP::A)
- #--按下A键时
- #★INP.trigger?(INP::A)
- #--按下A键时,判断是否重新按下
- #★INP.repeat?(INP::A)
- #---按下A键时,和 trigger? 不同的是,其考虑了连续按下按钮时的重复
- #★INP.dir4
- #--2 4 6 8 = 下 左 右 上
- #--*方向按钮未按下(或被看作与其相同)则返回 0
- #★INP.dir8
- #--2 4 6 8 = 下 左 右 上
- #--1 3 7 9 = 下左 左上 右下 上右
- #--[下,左,右,上]
- #-- + + + +
- #--[左,上,下,右]
- #--*方向按钮未按下(或被看作与其相同)则返回 0
- #◆四方向自定义按键示例:
- #--
- #case INP.dir4([INP::S,INP::A,INP::D,INP::W])
- # when 2
- # when 6
- # ...
- #end
- #◆八方向自定义按键示例:
- #--
- #case INP.dir8([INP::S,INP::A,INP::D,INP::W])
- # when 2
- # when 6
- # ...
- # when 1
- # when 3
- # ...
- #end
- #-----------------------------------------------------------------------------
- module INP
- #*默认值设定
- SPEEDLV = 6 #自定义速度等级(帧)*repeat?
- SPEED = 3 #自定义刷新速度(帧)*repeat?
- D4 = '[DOWN,LEFT,RIGHT,UP]' 默认方向键 *dir4 or dir8
- #--------------------------------------------------------------------------
- BUTTON_L = 0x01 # left mouse button
- BUTTON_R = 0x02 # right mouse button
- BUTTON_M = 0x04 # middle mouse button
- BUTTON_4 = 0x05 # 4th mouse button
- BUTTON_5 = 0x06 # 5th mouse button
- #--------------------------------------------------------------------------
- BACK = 0x08 # BACKSPACE key
- TAB = 0x09 # TAB key
- RETURN = 0x0D # ENTER key
- SHIFT = 0x10 # SHIFT key
- CTLR = 0x11 # CTLR key
- ALT = 0x12 # ALT key
- PAUSE = 0x13 # PAUSE key
- CAPITAL = 0x14 # CAPS LOCK key
- ESCAPE = 0x1B # ESC key
- SPACE = 0x20 # SPACEBAR
- PRIOR = 0x21 # PAGE UP key
- NEXT = 0x22 # PAGE DOWN key
- ENDS = 0x23 # END key
- HOME = 0x24 # HOME key
- LEFT = 0x25 # LEFT ARROW key
- UP = 0x26 # UP ARROW key
- RIGHT = 0x27 # RIGHT ARROW key
- DOWN = 0x28 # DOWN ARROW key
- SELECT = 0x29 # SELECT key
- PRINT = 0x2A # PRINT key
- SNAPSHOT = 0x2C # PRINT SCREEN key
- INSERT = 0x2D # INS key
- DELETE = 0x2E # DEL key
- #--------------------------------------------------------------------------
- U0 = 0x30 # 0 key
- U1 = 0x31 # 1 key
- U2 = 0x32 # 2 key
- U3 = 0x33 # 3 key
- U4 = 0x34 # 4 key
- U5 = 0x35 # 5 key
- U6 = 0x36 # 6 key
- U7 = 0x37 # 7 key
- U8 = 0x38 # 8 key
- U9 = 0x39 # 9 key
- #--------------------------------------------------------------------------
- A = 0x41 # A key
- B = 0x42 # B key
- C = 0x43 # C key
- D = 0x44 # D key
- E = 0x45 # E key
- F = 0x46 # F key
- G = 0x47 # G key
- H = 0x48 # H key
- I = 0x49 # I key
- J = 0x4A # J key
- K = 0x4B # K key
- L = 0x4C # L key
- M = 0x4D # M key
- N = 0x4E # N key
- O = 0x4F # O key
- P = 0x50 # P key
- Q = 0x51 # Q key
- R = 0x52 # R key
- S = 0x53 # S key
- T = 0x54 # T key
- U = 0x55 # U key
- V = 0x56 # V key
- W = 0x57 # W key
- X = 0x58 # X key
- Y = 0x59 # Y key
- Z = 0x5A # Z key
- #--------------------------------------------------------------------------
- LWIN = 0x5B # Left Windows key (Microsoft Natural keyboard)
- RWIN = 0x5C # Right Windows key (Natural keyboard)
- APPS = 0x5D # Applications key (Natural keyboard)
- #--------------------------------------------------------------------------
- NUMPAD0 = 0x60 # Numeric keypad 0 key
- NUMPAD1 = 0x61 # Numeric keypad 1 key
- NUMPAD2 = 0x62 # Numeric keypad 2 key
- NUMPAD3 = 0x63 # Numeric keypad 3 key
- NUMPAD4 = 0x64 # Numeric keypad 4 key
- NUMPAD5 = 0x65 # Numeric keypad 5 key
- NUMPAD6 = 0x66 # Numeric keypad 6 key
- NUMPAD7 = 0x67 # Numeric keypad 7 key
- NUMPAD8 = 0x68 # Numeric keypad 8 key
- NUMPAD9 = 0x69 # Numeric keypad 9 key
- MULTIPLY = 0x6A # Multiply key (*)
- ADD = 0x6B # Add key (+)
- SEPARATOR = 0x6C # Separator key
- SUBTRACT = 0x6D # Subtract key (-)
- DECIMAL = 0x6E # Decimal key
- DIVIDE = 0x6F # Divide key (/)
- #--------------------------------------------------------------------------
- F1 = 0x70 # F1 key
- F2 = 0x71 # F2 key
- F3 = 0x72 # F3 key
- F4 = 0x73 # F4 key
- F5 = 0x74 # F5 key
- F6 = 0x75 # F6 key
- F7 = 0x76 # F7 key
- F8 = 0x77 # F8 key
- F9 = 0x78 # F9 key
- F10 = 0x79 # F10 key
- F11 = 0x7A # F11 key
- F12 = 0x7B # F12 key
- #--------------------------------------------------------------------------
- NUMLOCK = 0x90 # NUM LOCK key
- SCROLL = 0x91 # SCROLL LOCK key
- #--------------------------------------------------------------------------
- LSHIFT = 0xA0 # Left SHIFT key
- RSHIFT = 0xA1 # Right SHIFT key
- LCONTROL = 0xA2 # Left CONTROL key
- RCONTROL = 0xA3 # Right CONTROL key
- L_ALT = 0xA4 # Left ALT key
- R_ALT = 0xA5 # Right ALT key
- #--------------------------------------------------------------------------
- SEP = 0xBC # , key
- DASH = 0xBD # - key
- DOTT = 0xBE # . Key
- #--------------------------------------------------------------------------
- DIR = eval(D4)
- #--------------------------------------------------------------------------
- @tr = false
- @re = 0
- GetKeyState =
- Win32API.new("user32","GetAsyncKeyState",['I'],'I')
- def self.press?(key)
- i = GetKeyState.call(key)
- if i != 0
- return true
- end
- end
- def self.trigger?(key)
- i = GetKeyState.call(key)
- if i != 0 and !@tr
- @tr = true
- return true
- elsif i == 0 and @tr
- @tr = false
- end
- end
- def self.repeat?(key)
- i = GetKeyState.call(key)
- if i == 0
- @re = 0
- end
- if i != 0
- if @re.xin?(1,SPEEDLV)
- @re -= 1
- return false
- end
- @re += [SPEED,SPEEDLV].min
- return true
- end
- end
- def self.dir4(dir=DIR);n=-1
- dir.size.times { n+=1
- if GetKeyState.call(dir[n]) != 0
- case n
- when 0 ;return 2
- when 1 ;return 4
- when 2 ;return 6
- when 3 ;return 8
- end
- end }
- return 0
- end
- def self.dir8(dir=DIR,dir2=[]);n=-1
- if dir2.empty?
- d8 = dir
- dir2 = [d8[1],d8[3],d8[0],d8[2]]
- end
- dir.size.times { n+=1
- if GetKeyState.call(dir[n]) != 0 and GetKeyState.call(dir2[n]) != 0
- case n
- when 0 ;return 1#左下
- when 1 ;return 3#左上
- when 2 ;return 7#右下
- when 3 ;return 9#右上
- end
- end };n=-1
- dir.size.times { n+=1
- if GetKeyState.call(dir[n]) != 0
- case n
- when 0 ;return 2
- when 1 ;return 4
- when 2 ;return 6
- when 3 ;return 8
- end
- end }
- return 0
- end
- end
- class Object
- def xin?(x,y)
- if x <= self and self <= y
- return true
- else
- return false
- end
- end
- end
复制代码 啊呜 大概就是这样 |
评分
-
查看全部评分
|