RPG-Maker Quartier

Hier dreht sich alles um die RPG-Maker-Reihe von ASCII/Enterbrain. Der RPG-Maker ist ein Tool, mit dem du dir dein eigenes kleines Rollenspiel erstellen kannst. Du findest hier alles, was du dazu brauchst. Aber natürlich umfasst die Community noch mehr!
Aktuelle Zeit: Di Mär 03, 2020 3:01

Alle Zeiten sind UTC + 1 Stunde



Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast



Ein neues Thema erstellen Auf das Thema antworten  [ 7 Beiträge ] 
Autor Nachricht
Offline
Rotfüchschen
Rotfüchschen
Beiträge: 227
 Betreff des Beitrags: CAPS LOCK-Status abfragen
BeitragVerfasst: Do Mai 19, 2011 8:32 
Hallo zusammen,

ich wollte mal wissen, ob es eine Möglichkeit gibt, zu prüfen, ob der Status der Umschalttaste aktiv ist.

Und zwar benutze ich folgendes Script von Glitchfinder:
Code:
#≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
# ** Glitchfinder's Key Input Module              [RPG Maker XP] [RPG Maker VX]
#    Version 1.00
#------------------------------------------------------------------------------
#  This script helps scripters to use the full range of keys on any keyboard,
#  without being limited by the default Input Module.
#==============================================================================
# * Version History
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   Version 1.00 ------------------------------------------------- (2010-03-18)
#     - Initial version
#     - Author: Glitchfinder
#==============================================================================
# * Instructions
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#  Place this script above Main, and below the default scripts. (I realize this
#  is obvious to most, but some people don't get it.)
#
#  This module is automatically updated by the default Input module, which
#  means that the only time you need to call the update method is in a scene
#  that does not update the default Input module.
#
#  This module does not break the functionality of the default Input module.
#
#  If you wish to read keys from a gamepad, you must still use the default
#  input module to do so.
#
#  To use this module, simply use one of the four methods (press?(key),
#  trigger?(key), repeat?(key), or release?(key)), where key is the index of
#  the key you want to check. Key may also be used as Keys::KEYNAME. For a list
#  of acceptable key names, look below the header.
#==============================================================================
# * Method List
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#  Keys.update
#    Updates keyboard input. Calls to this method are not necessary unless the
#    default Input module is not being updated.
#
#  Keys.press?(key)
#    Determines whether the button determined by key is currently being
#    pressed. If the button is being pressed, returns true. If not, returns
#    false.
#
#  Keys.trigger?(key)
#    Determines whether the button determined by key is being pressed again.
#    "Pressed again" is seen as time having passed between the button being not
#    pressed and being pressed. If the button is being pressed, returns true.
#    If not, returns false.
#
#  Keys.repeat?(key)
#    Determines whether the button determined by key is being pressed again.
#    Unlike trigger?(), this takes into account the repeat input of a button
#    being held down continuously. If the button is being pressed, returns
#    true. If not, returns false.
#
#  Keys.release?(key)
#    Determines whether the button determined by key has just been released. If
#    the button has been released, returns true. If not, returns false.
#==============================================================================
# *Glitchfinder's Advice
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#  This script is meant for people with a medium or advanced level of scripting
#  knowledge and ability, or for those using scripts that require this module.
#==============================================================================
# * Contact
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#  Glitchfinder, the author of this script, may be contacted through his
#  website, found at http://www.glitchkey.com
#
#  You may also find Glitchfinder at http://www.hbgames.org
#==============================================================================
# * Usage
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#  This script may be used with the following terms and conditions:
#
#    1. This script is free to use in any noncommercial project. If you wish to
#       use this script in a commercial (paid) project, please contact
#       Glitchfinder at his website.
#    2. This script may only be hosted at the following domains:
#         http://www.glitchkey.com
#         http://www.hbgames.org
#    3. If you wish to host this script elsewhere, please contact Glitchfinder.
#    4. If you wish to translate this script, please contact Glitchfinder. He
#       will need the web address that you plan to host the script at, as well
#       as the language this script is being translated to.
#    5. This header must remain intact at all times.
#    6. Glitchfinder remains the sole owner of this code. He may modify or
#       revoke this license at any time, for any reason.
#    7. Any code derived from code within this script is owned by Glitchfinder,
#       and you must have his permission to publish, host, or distribute his
#       code.
#    8. This license applies to all code derived from the code within this
#       script.
#    9. If you use this script within your project, you must include visible
#       credit to Glitchfinder, within reason.
#≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

#==============================================================================
# ** Keys
#------------------------------------------------------------------------------
#  This module performs key input processing
#==============================================================================

module Keys
  #--------------------------------------------------------------------------
  # * Miscellaneous Keys
  #--------------------------------------------------------------------------
  CANCEL              = 0x03 # Control-Break Processing
  BACKSPACE           = 0x08 # Backspace Key
  TAB                 = 0x09 # Tab Key
  CLEAR               = 0x0C # Clear Key
  RETURN              = 0x0D # Enter Key
  SHIFT               = 0x10 # Shift Key
  CONTROL             = 0x11 # Ctrl Key
  MENU                = 0x12 # Alt Key
  PAUSE               = 0x13 # Pause Key
  ESCAPE              = 0x1B # Esc Key
  CONVERT             = 0x1C # IME Convert Key
  NONCONVERT          = 0x1D # IME Nonconvert Key
  ACCEPT              = 0x1E # IME Accept Key
  SPACE               = 0x20 # Space Bar Key (Space, usually blank)
  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
  EXECUTE             = 0x2B # Execute Key
  SNAPSHOT            = 0x2C # Print Screen Key
  DELETE              = 0x2E # Delete Key
  HELP                = 0x2F # Help Key
  LSHIFT              = 0xA0 # Left Shift Key
  RSHIFT              = 0xA1 # Right Shift Key
  LCONTROL            = 0xA2 # Left Control Key (Ctrl)
  RCONTROL            = 0xA3 # Right Control Key (Ctrl)
  LMENU               = 0xA4 # Left Menu Key (Alt)
  RMENU               = 0xA5 # Right Menu Key (Alt)
  PACKET              = 0xE7 # Used to Pass Unicode Characters as Keystrokes
  #--------------------------------------------------------------------------
  # * Number Keys
  #--------------------------------------------------------------------------
  N0                  = 0x30 # 0 Key
  N1                  = 0x31 # 1 Key
  N2                  = 0x32 # 2 Key
  N3                  = 0x33 # 3 Key
  N4                  = 0x34 # 4 Key
  N5                  = 0x35 # 5 Key
  N6                  = 0x36 # 6 Key
  N7                  = 0x37 # 7 Key
  N8                  = 0x38 # 8 Key
  N9                  = 0x39 # 9 Key
  #--------------------------------------------------------------------------
  # * Letter Keys
  #--------------------------------------------------------------------------
  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
  #--------------------------------------------------------------------------
  # * Windows Keys
  #--------------------------------------------------------------------------
  LWIN                = 0x5B # Left Windows Key (Natural keyboard)
  RWIN                = 0x5C # Right Windows Key (Natural Keyboard)
  APPS                = 0x5D # Applications Key (Natural keyboard)
  SLEEP               = 0x5F # Computer Sleep Key
  BROWSER_BACK        = 0xA6 # Browser Back Key
  BROWSER_FORWARD     = 0xA7 # Browser Forward Key
  BROWSER_REFRESH     = 0xA8 # Browser Refresh Key
  BROWSER_STOP        = 0xA9 # Browser Stop Key
  BROWSER_SEARCH      = 0xAA # Browser Search Key
  BROWSER_FAVORITES   = 0xAB # Browser Favorites Key
  BROWSER_HOME        = 0xAC # Browser Start and Home Key
  VOLUME_MUTE         = 0xAD # Volume Mute Key
  VOLUME_DOWN         = 0xAE # Volume Down Key
  VOLUME_UP           = 0xAF # Volume Up Key
  MEDIA_NEXT_TRACK    = 0xB0 # Next Track Key
  MEDIA_PREV_TRACK    = 0xB1 # Previous Track Key
  MEDIA_STOP          = 0xB2 # Stop Media Key
  MEDIA_PLAY_PAUSE    = 0xB3 # Play/Pause Media Key
  LAUNCH_MAIL         = 0xB4 # Start Mail Key
  LAUNCH_MEDIA_SELECT = 0xB5 # Select Media Key
  LAUNCH_APP1         = 0xB6 # Start Application 1 Key
  LAUNCH_APP2         = 0xB7 # Start Application 2 Key
  PROCESSKEY          = 0xE5 # IME Process Key
  ATTN                = 0xF6 # Attn Key
  CRSEL               = 0xF7 # CrSel Key
  EXSEL               = 0xF8 # ExSel Key
  EREOF               = 0xF9 # Erase EOF Key
  PLAY                = 0xFA # Play Key
  ZOOM                = 0xFB # Zoom Key
  PA1                 = 0xFD # PA1 Key
  #--------------------------------------------------------------------------
  # * Number Pad Keys
  #--------------------------------------------------------------------------
  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 (/)
  #--------------------------------------------------------------------------
  # * Function Keys
  #--------------------------------------------------------------------------
  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
  F13                 = 0x7C # F13 Key
  F14                 = 0x7D # F14 Key
  F15                 = 0x7E # F15 Key
  F16                 = 0x7F # F16 Key
  F17                 = 0x80 # F17 Key
  F18                 = 0x81 # F18 Key
  F19                 = 0x82 # F19 Key
  F20                 = 0x83 # F20 Key
  F21                 = 0x84 # F21 Key
  F22                 = 0x85 # F22 Key
  F23                 = 0x86 # F23 Key
  F24                 = 0x87 # F24 Key
  #--------------------------------------------------------------------------
  # * Toggle Keys
  #--------------------------------------------------------------------------
  CAPITAL             = 0x14 # Caps Lock Key
  KANA                = 0x15 # IME Kana Mode Key
  HANGUL              = 0x15 # IME Hangul Mode Key
  JUNJA               = 0x17 # IME Junja Mode Key
  FINAL               = 0x18 # IME Final Mode Key
  HANJA               = 0x19 # IME Hanja Mode Key
  KANJI               = 0x19 # IME Kanji Mode Key
  MODECHANGE          = 0x1F # IME Mode Change Request Key
  INSERT              = 0x2D # Insert Key
  NUMLOCK             = 0x90 # Num Lock Key
  SCROLL              = 0x91 # Scroll Lock Key
  #--------------------------------------------------------------------------
  # * OEM Keys (Vary by keyboard)
  #--------------------------------------------------------------------------
  OEM_1               = 0xBA # Misc Characters (; : in USA 101/102 Keyboards)
  OEM_PLUS            = 0xBB # + = Key
  OEM_COMMA           = 0xBC # , < Key
  OEM_MINUS           = 0xBD # - _ Key
  OEM_PERIOD          = 0xBE # . > Key
  OEM_2               = 0xBF # Misc Characters (/ ? in USA 101/102 Keyboards)
  OEM_3               = 0xC0 # Misc Characters (` ~ in USA 101/102 Keyboards)
  OEM_4               = 0xDB # Misc Characters ([ { in USA 101/102 Keyboards)
  OEM_5               = 0xDC # Misc Characters (\ | in USA 101/102 Keyboards)
  OEM_6               = 0xDD # Misc Characters (] } in USA 101/102 Keyboards)
  OEM_7               = 0xDE # Misc Characters (' " in USA 101/102 Keyboards)
  OEM_8               = 0xDF # Misc Characters (Varies by Keyboard)
  OEM_9               = 0xE1 # OEM Specific
  OEM_10              = 0x92 # OEM Specific
  OEM_11              = 0x93 # OEM Specific
  OEM_12              = 0x94 # OEM Specific
  OEM_13              = 0x95 # OEM Specific
  OEM_14              = 0x96 # OEM Specific
  OEM_15              = 0xE3 # OEM Specific
  OEM_16              = 0xE4 # OEM Specific
  OEM_17              = 0xE6 # OEM Specific
  OEM_18              = 0xE9 # OEM Specific
  OEM_19              = 0xEA # OEM Specific
  OEM_20              = 0xEB # OEM Specific
  OEM_21              = 0xEC # OEM Specific
  OEM_22              = 0xED # OEM Specific
  OEM_23              = 0xEE # OEM Specific
  OEM_24              = 0xEF # OEM Specific
  OEM_25              = 0xF1 # OEM Specific
  OEM_26              = 0xF2 # OEM Specific
  OEM_27              = 0xF3 # OEM Specific
  OEM_28              = 0xF4 # OEM Specific
  OEM_29              = 0xF5 # OEM Specific
  OEM_102             = 0xE2 # Angle Bracket or Backslash on RT-102 Keyboards
  OEM_CLEAR           = 0xFE # Clear Key
  #--------------------------------------------------------------------------
  # * Declare Module Variables
  #--------------------------------------------------------------------------
  # Create string for unpacking input
  @unpack_string = 'b'*256
  # Generate blank input arrays
  @last_array = '0'*256
  @press = Array.new(256, false)
  @trigger = Array.new(256, false)
  @repeat = Array.new(256, false)
  @release = Array.new(256, false)
  # Generate blank counter array
  @repeat_counter = Array.new(256, 0)
  # Declare keyboard API
  @getKeyboardState = Win32API.new('user32', 'GetKeyboardState', ['P'], 'V')
  @getAsyncKeyState = Win32API.new('user32', 'GetAsyncKeyState', 'i', 'i')
  # Call current keyboard state
  @getKeyboardState.call(@last_array)
  # Set previous keyboard state
  @last_array = @last_array.unpack(@unpack_string)
  # Cycle through keys
  for i in 0...@last_array.size
    # Set pressed key state
    @press[i] = @getAsyncKeyState.call(i) == 0 ? false : true
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def self.update
    # Clear input arrays
    @trigger = Array.new(256, false)
    @repeat = Array.new(256, false)
    @release = Array.new(256, false)
    # create blank input array
    array = '0'*256
    # Call current keyboard state
    @getKeyboardState.call(array)
    # Unpack key array
    array = array.unpack(@unpack_string)
    # Cycle through all keys
    for i in 0...array.size
      # If the current key state does not match the previous state
      if array[i] != @last_array[i]
        # Set current key state
        @press[i] = @getAsyncKeyState.call(i) == 0 ? false : true
        # If the repeat counter is at 0
        if @repeat_counter[i] <= 0 && @press[i]
          # Set the key to repeat
          @repeat[i] = true
          # Set the repeat counter to 15 frames
          @repeat_counter[i] = 15
        end
        # If the key is not being pressed
        if !@press[i]
          # Set the key to released
          @release[i] = true
        # If the key is being pressed
        else
          # Set the key to triggered
          @trigger[i] = true
        end
      # If the key state is the same
      else
        # If the key is set to pressed
        if @press[i] == true
          # Set the current key state
          @press[i] = @getAsyncKeyState.call(i) == 0 ? false : true
          # Set the key to released if it is no longer being pressed
          @release[i] = true if !@press[i]
        end
        # If the repeat counter is greater than 0 and the key is pressed
        if @repeat_counter[i] > 0 && @press[i] == true
          # Cycle the repeat counter down one frame
          @repeat_counter[i] -= 1
        # If the repeat counter is 0 or less and the key is pressed
        elsif @repeat_counter[i] <= 0 && @press[i] == true
          # Set the key to repeat
          @repeat[i] = true
          # Set the repeat counter to 15 frames
          @repeat_counter[i] = 3
        # If the repeat counter does not equal 0
        elsif @repeat_counter[i] != 0
          # Set the repeat counter to 0
          @repeat_counter[i] = 0
        end
      end
    end
    # Set the previous keyboard state
    @last_array = array
  end
  #--------------------------------------------------------------------------
  # * Get Key Pressed State
  #     key : key index
  #--------------------------------------------------------------------------
  def self.press?(key)
    # Return key pressed state
    return @press[key]
  end
  #--------------------------------------------------------------------------
  # * Get Key Triggered State
  #     key : key index
  #--------------------------------------------------------------------------
  def self.trigger?(key)
    # Return key triggered state
    return @trigger[key]
  end
  #--------------------------------------------------------------------------
  # * Get Key Repeated State
  #     key : key index
  #--------------------------------------------------------------------------
  def self.repeat?(key)
    # Return key repeated state
    return @repeat[key]
  end
  #--------------------------------------------------------------------------
  # * Get Key Released State
  #     key : key index
  #--------------------------------------------------------------------------
  def self.release?(key)
    # Return key released state
    return @release[key]
  end
 
end

#==============================================================================
# ** Input
#------------------------------------------------------------------------------
#  This module performs key input processing
#==============================================================================

module Input
  # Add class data
  class << self
    #------------------------------------------------------------------------
    # * Alias Methods
    #------------------------------------------------------------------------
    alias glitch_input_keys_update update
    #------------------------------------------------------------------------
    # * Frame Update
    #------------------------------------------------------------------------
    def update
      # Call original method
      glitch_input_keys_update
      # Update Keys module
      Keys.update
    end
  end
end


Mit folgender Methode überprüfe ich, ob irgendeine Taste gedrückt wurde, gebe den Dezimalwert dieses Keys zurück (und wandel diesen bei Texteingaben ggf. in ein Zeichen oder einen Buchstaben um):

Code:
def self.pressed?()
    #return the pressed key
    for i in 0..@press.size
      if(@press[i]==true)
        @press[i]=false
        return i
      end
    end
    return false
end


Das Problem ist jetzt, dass ich zwar überprüfen kann, ob die Umschalttaste gerade gedrückt wurde, aber nicht, ob ihr Status aktiv ist oder nicht.
Drücke ich bspw. die Taste "a", so erhalte ich immer den Wert 65, egal ob Shift/Capslock aktiv ist oder nicht (normal würde ich ja erwarten, dass ich den Wert 97 erhalte, wenn CAPS aktiviert ist...).

_________________
Bild


Nach oben
 Profil  
Mit Zitat antworten  
Offline
Official Oldschool
Official Oldschool
Benutzeravatar
Beiträge: 8917
Alter: 31
Wohnort: BRD, Thüringen
 Betreff des Beitrags: Re: CAPS LOCK-Status abfragen
BeitragVerfasst: Do Mai 19, 2011 13:03 
Füge den Code unter das Script ein.
Code:
class << Keys

  def toggle? key
    @last_array[key] % 2 == 1
  end

  def capslock?
    toggle? Keys::CAPITAL
  end

  def insert?
    toggle? Keys::INSERT
  end

  def numlock?
    toggle? Keys::NUMLOCK
  end

end


Danach müsstest du mit
Code:
Keys.capslock?

abfragen können ob die Capslock-Taste aktiv ist.

_________________


Nach oben
 Profil ICQ  
Mit Zitat antworten  
Offline
Rotfüchschen
Rotfüchschen
Beiträge: 227
 Betreff des Beitrags: Re: CAPS LOCK-Status abfragen
BeitragVerfasst: Do Mai 19, 2011 13:51 
Danke für die schnelle Antwort KD, aber irgendwie funktioniert das nicht.... das Ergebnis ist nie true ;<

_________________
Bild


Nach oben
 Profil  
Mit Zitat antworten  
Offline
Official Oldschool
Official Oldschool
Benutzeravatar
Beiträge: 8917
Alter: 31
Wohnort: BRD, Thüringen
 Betreff des Beitrags: Re: CAPS LOCK-Status abfragen
BeitragVerfasst: Do Mai 19, 2011 16:03 
Okay, neuer Versuch:
Code:
class << Keys

  def toggle? key
    @last_array[key] > 0
  end

  def capslock?
    toggle? Keys::CAPITAL
  end

  def insert?
    toggle? Keys::INSERT
  end

  def numlock?
    toggle? Keys::NUMLOCK
  end

end


Ich bin mir im übrigen nicht ganz sicher, ob dein Input-Script korrekt ist. Irgendwie ist das ganz merkwürdig programmiert.

_________________


Nach oben
 Profil ICQ  
Mit Zitat antworten  
Offline
Rotfüchschen
Rotfüchschen
Beiträge: 227
 Betreff des Beitrags: Re: CAPS LOCK-Status abfragen
BeitragVerfasst: Do Mai 19, 2011 16:26 
Vielen Dank KD,

kann es leider erst Morgen testen (hab's alles auf'm Firmen Notebook).
Hab das Script während der Arbeit zufällig entdeckt, und da mein altes veraltet war, habe ich das getestet. Und es läuft einwandfrei bei einzelnen Abfragen.

_________________
Bild


Nach oben
 Profil  
Mit Zitat antworten  
Offline
Official Oldschool
Official Oldschool
Benutzeravatar
Beiträge: 8917
Alter: 31
Wohnort: BRD, Thüringen
 Betreff des Beitrags: Re: CAPS LOCK-Status abfragen
BeitragVerfasst: Do Mai 19, 2011 19:56 
Ich hab das Script mal ausprobiert und bei mir funktioniert es hinten und vorne nicht (trigger? funktioniert als einziges, die anderen Sachen wie repeat? und press? spinnen allerdings rum). Allerdings habe ich es auf Ubuntu per Wine gestartet, von daher kann es sich dort auch etwas anders verhalten als unter richtigem Windows.

Nichtsdestotrotz macht das Script einfach keinen Sinn. Es werden die falschen Sachen abgefragt, LSB und MSB verwechselt usw.

Ich habe das Script mal korrigiert. Hier der aktualisierte Code:
Code:
class String
  unless method_defined? :ord
    def ord
      self[0]
    end
  end
end
module Keys

  MEMORY_SIZE = 16
  REPEAT_TIME = 4
 
 
  MSB = 128
  LSB = 1
 
  @counter = 0
  @key_stores = Array.new(MEMORY_SIZE) {0.chr * 256}
  @dll_func = Win32API.new("user32", "GetKeyboardState", %W(p), "i")

  class << self
   
    def update
      @counter = (@counter+1) % MEMORY_SIZE
      @dll_func.call(current_store)
    end
   
    def current_store
      @key_stores[@counter]
    end
   
    def previous_store(n=1)
      @key_stores[(@counter - n) % MEMORY_SIZE]
    end
   
    def press? key, store=current_store
      store[key] & MSB == MSB
    end
   
    def trigger? key
      press?(key) && !press?(key, previous_store)
    end
   
    def release? key
      !press?(key) && press?(key, previous_store)
    end
   
    def repeat? key
      trigger?(key) || (0...MEMORY_SIZE).all? {|n| press?(key, previous_store(n)) } &&
      @counter % REPEAT_TIME == 0
    end
   
    def toggle? key
      current_store[key] & LSB == LSB
    end
   
    # Methoden capital?, scroll?, numlock?, insert? usw. für alle TOGGLE-Tasten
    # werden ebenfalls definiert
    %W(CAPITAL HANGUL JUNJA FINAL HANJA KANJI MODECHANGE
      INSERT NUMLOCK SCROLL).each do |togglekey|
        konst = Keys.const_get(togglekey)
        define_method(:"#{togglekey.downcase}?") do
          toggle? konst
        end
    end

    alias capslock? capital?
   
    # gibt den gerade gedrückten Buchstaben aus
    def get_letter
      char = ("A".."Z").find {|letter|
        repeat? letter.ord
      }
      write_big = press?(SHIFT)
      write_big = !write_big if capslock?
      char ? (write_big ? char : char.downcase) : nil
    end 
   
  end
 
end


Die ganzen Konstanten für die Tasten kannst du behalten. Das Script kann auch einfach unter das bestehende geschrieben werden, es ersetzt ja die Methoden. Ich habe auch eine Methode get_letter hinzugefügt, welche den eingegebenen Buchstaben zurückgibt (und dabei die Groß/Klein-Schreibung durch die Capslock und Shift-Taste beachtet). Ich würde dir dennoch raten das Script nochmal ausgiebig zu testen. Ich verwende z.B., anders als in den anderen Inputskripten, kein GetAsyncKeyState, weil ich bislang nie so ganz verstanden habe wozu das gut sein soll. Theoretisch könnte es passieren, dass wenn das Spiel laggt und man extrem schnell auf die Tasten haut, diese nicht erkannt werden. Aber ich hab das nie reproduzieren können. k.a. ob es irgendwelche Nachteile hat, nur GetKeyboardState und kein GetAsyncKeyState zu verwenden.

_________________


Nach oben
 Profil ICQ  
Mit Zitat antworten  
Offline
Rotfüchschen
Rotfüchschen
Beiträge: 227
 Betreff des Beitrags: Re: CAPS LOCK-Status abfragen
BeitragVerfasst: Fr Mai 20, 2011 7:16 
Vielen vielen Dank KD. Dein aktualisiertes Script läuft perfekt. Vielen Dank für deine Mühe!

Also das alte Script lief auf jeden Fall mit press? und repeat?, die anderen Funktionne hatte ich jetzt nicht so sehr getestet. Es gab weder Lags, noch sind mir irgendwelche Bugs aufgefallen.

Dein Script ist echt super. Danke nochmals!

_________________
Bild


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 7 Beiträge ] 

Alle Zeiten sind UTC + 1 Stunde


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de