Vlue

Special Keybinds

Oct 14th, 2012
3,586
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Special Keybinds v1.4a
  2. #----------#
  3. #Features: A way to use almost any key on your keyboard to toggle switches,
  4. #           add to variables, or call scenes! Doesn't that sound just neat!
  5. #
  6. #Usage:   Press the set up keybind!
  7. #        
  8. #Customization: Add to the KI_KEYBINDS hash as needed!
  9. #                Details below!
  10. #
  11. #----------#
  12. #-- Script by: V.M of D.T
  13. #
  14. #- Questions or comments can be:
  15. #    given by email: sumptuaryspade@live.ca
  16. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  17. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  18. #
  19. #--- Free to use in any project, commercial or non-commercial, with credit given
  20. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  21.  
  22. #This is where you set up your keybinds. It goes either:
  23. # Key symbol => [cond, :scene, scene_name],
  24. # Key Symbol => [cond, :var, var_id, amount],
  25. # Key Symbol => [cond, :switch, switch_id],
  26. # Key Symbol => [cond, :script, "script call"],
  27. #
  28. # Cond (condition) is either :press or :trigger. :press is continuous while
  29. #  :trigger runs once per key press.
  30. #
  31. # Key Symbols are the names of the key, from A-Z, N0-N9, or many of the
  32. # named keys! They are listed as symbols below for semi-easy reference!
  33. #
  34. #Adding and removing keybinds while in game with simple script calls:
  35. #  $ki_keybinds.delete(symbol)
  36. #  $ki_keybinds[symbol] = [keybind setup (see above)]
  37. #Symbol is any Key Symbol as listed under Input below
  38.  
  39. $ki_keybinds= { :N1 => [:trigger, :scene, Scene_Title],
  40.                 :N2 => [:trigger, :var, 1, 5],
  41.                 :N3 => [:trigger, :switch, 1],
  42.                 :N4 => [:trigger, :script, "$game_party.gain_gold(1000)"],
  43.                 :W => [:press, :script, "$game_player.move_by_int(8)",nil,1],
  44.                 :A => [:press, :script, "$game_player.move_by_int(4)",nil,1],
  45.                 :S => [:press, :script, "$game_player.move_by_int(2)",nil,1],
  46.                 :D => [:press, :script, "$game_player.move_by_int(6)",nil,1],
  47.                 }
  48.  
  49. module Keyboard_Input
  50.  
  51.   ASKS = Win32API.new 'user32', 'GetAsyncKeyState', ['p'], 'i'
  52.  
  53.   INPUT = { :backspace => 0x08, :tab => 0x09, :enter => 0x0D, :shift => 0x10,
  54.             :ctrl => 0x11, :alt => 0x12, :pause => 0x13, :caps => 0x14,
  55.             :escape => 0x1B, :space => 0x20, :pageup => 0x21, :pagedown => 0x22,
  56.             :end => 0x23, :home => 0x24, :left => 0x25, :up => 0x26,
  57.             :right => 0x27, :down => 0x28, :print => 0x2C, :insert => 0x2D,
  58.             :delete => 0x2E,
  59.            
  60.             :N0 => 0x30, :N1 => 0x31, :N2 => 0x32, :N3 => 0x33,
  61.             :N4 => 0x34, :N5 => 0x35, :N6 => 0x36, :N7 => 0x37, :N8 => 0x38,
  62.             :N9 => 0x39,
  63.            
  64.             :A => 0x41, :B => 0x42, :C => 0x43, :D => 0x44, :E => 0x45, :F => 0x46,
  65.             :G => 0x47, :H => 0x48, :I => 0x49, :J => 0x4A, :K => 0x4B, :L => 0x4C,
  66.             :M => 0x4D, :N => 0x4E, :O => 0x4F, :P => 0x50, :Q => 0x51, :R => 0x52,
  67.             :S => 0x53, :T => 0x54, :U => 0x55, :V => 0x56, :W => 0x57, :X => 0x58,
  68.             :Y => 0x59, :Z => 0x5A,
  69.            
  70.             :F1 => 0x70, :F2 => 0x71, :F3 => 0x72,
  71.             :F4 => 0x73, :F5 => 0x74, :F6 => 0x75, :F7 => 0x76, :F8 => 0x77,
  72.             :F9 => 0x78, :F10 => 0x79, :F11 => 0x7A, :F12 => 0x7B,
  73.            
  74.             :num => 0x90,
  75.             :scroll => 0x91, :lshift => 0xA0, :rshift => 0xA1, :lctrl => 0xA2,
  76.             :rctrl => 0xA3, :lalt => 0xA4, :ralt => 0xA5, :colon => 0xBa,
  77.             :plus => 0xBB, :comma => 0xBC, :minus => 0xBD, :period => 0xBE,
  78.             :slash => 0xBF, :tilde => 0xC0, :lbrace => 0xDB, :backslash => 0xDC,
  79.             :rbrace => 0xDD, :quote => 0xDE  }
  80.            
  81.   def self.press?(symbol, delay = 30)
  82.     return unless @delay == 0 or @delay.nil?
  83.     return false if ASKS.call(INPUT[symbol]) == 0
  84.     @delay = delay
  85.     return true
  86.   end
  87.   def self.trigger?(symbol)
  88.     return unless @pressed
  89.     return false if @pressed[symbol]
  90.     return false if ASKS.call(INPUT[symbol]) == 0
  91.     @pressed[symbol] = true
  92.     return true
  93.   end
  94.   def self.update
  95.     setup unless @pressed
  96.     @pressed.each do |key, val|
  97.       @pressed[key] = ASKS.call(INPUT[key]) != 0
  98.     end
  99.     return if @delay == 0
  100.     @delay -= 1 unless @delay.nil?
  101.   end
  102.   def self.setup
  103.     @pressed = {}
  104.   end
  105. end
  106.  
  107. class Scene_Base
  108.   alias cekb_update update
  109.   def update
  110.     cekb_update
  111.     cekb_input_update
  112.     Keyboard_Input.update
  113.   end
  114.   def cekb_input_update
  115.     $ki_keybinds.each {|key, value|
  116.       if value[0] == :press
  117.         next unless Keyboard_Input.press?(key, value[4] ? value[4] : 30)
  118.       elsif value[0] == :trigger
  119.         next unless Keyboard_Input.trigger?(key)
  120.       end
  121.       next unless self.is_a?(Scene_Map)
  122.       next if $game_map.interpreter.running?
  123.       SceneManager.call(value[2]) if value[1] == :scene
  124.       $game_variables[value[2]] += value[3] if value[1] == :var
  125.       if value[1] == :switch
  126.         id = value[2]
  127.         switch = $game_switches[value[2]]
  128.         switch == false ? $game_switches[id] = true : $game_switches[id] = false
  129.       end
  130.       eval(value[2]) if value[1] == :script
  131.     }
  132.   end
  133. end
  134.  
  135. class Game_Player
  136.   def move_by_int(dir)
  137.     return if !movable? || $game_map.interpreter.running?
  138.     move_straight(dir) if dir > 0
  139.   end
  140. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×