• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Wrapper] KeyboardEvent

Kazeon

Hosted Project: EC
Level 34
Joined
Oct 12, 2011
Messages
3,449
which one do you prefer guys?
Mine
JASS:
if KeyboardEvent.whatEvent == KeyboardEvent.ARROW_UP_PRESS then
    call BJDebugMsg(GetPlayerName(KeyboardEvent.triggerPlayer) + " pressed up arrow")
endif
or Bribe's
JASS:
        if .getKeyName(arrow) == ARROW_KEY_LEFT then
            if pressed then
                call BJDebugMsg("press left")
            else
                call BJDebugMsg("release left")
            endif
        endif

because I found his library several minutes after I did some minor updates. If Bribe's is completely better, then just GY this ;)
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
Suggestion

Either 1
JASS:
        private static method onPress takes nothing returns boolean
            call TriggerEvaluate(trig)
            set whatEvent = GetHandleId(GetTriggeringTrigger())-GetHandleId(trigger[0])
            set triggerPlayer = GetTriggerPlayer()
            return false
        endmethod

or 2
JASS:
        static integer OFFSET=0
        //...
        
        private static method onPress takes nothing returns boolean
            call TriggerEvaluate(trig)
            set whatEvent = GetHandleId(GetTriggeringTrigger())-OFFSET
            set triggerPlayer = GetTriggerPlayer()
            return false
        endmethod
        
        private static method onInit takes nothing returns nothing
            local integer i = 0
            local player p
           
            loop
                exitwhen i > 8
                set trigger[i] = CreateTrigger()
                set i = i + 1
            endloop
            // insert
            set OFFSET=GetHandleId(trigger[0])
            // the line above
            set i = 0
            loop
                exitwhen i > 11
                set p = Player(i)
                call TriggerRegisterPlayerEvent(trigger[ARROW_UP_PRESS], p, EVENT_PLAYER_ARROW_UP_DOWN)
                call TriggerRegisterPlayerEvent(trigger[ARROW_UP_RELEASE], p, EVENT_PLAYER_ARROW_UP_UP)
                call TriggerRegisterPlayerEvent(trigger[ARROW_DOWN_PRESS], p, EVENT_PLAYER_ARROW_DOWN_DOWN)
                call TriggerRegisterPlayerEvent(trigger[ARROW_DOWN_RELEASE], p, EVENT_PLAYER_ARROW_DOWN_UP)
                call TriggerRegisterPlayerEvent(trigger[ARROW_LEFT_PRESS], p, EVENT_PLAYER_ARROW_LEFT_DOWN)
                call TriggerRegisterPlayerEvent(trigger[ARROW_LEFT_RELEASE], p, EVENT_PLAYER_ARROW_LEFT_UP)
                call TriggerRegisterPlayerEvent(trigger[ARROW_RIGHT_PRESS], p, EVENT_PLAYER_ARROW_RIGHT_DOWN)
                call TriggerRegisterPlayerEvent(trigger[ARROW_RIGHT_RELEASE], p, EVENT_PLAYER_ARROW_RIGHT_UP)
                call TriggerRegisterPlayerEvent(trigger[END_CINEMATIC], p, EVENT_PLAYER_END_CINEMATIC)
                set i = i + 1
            endloop
            set i = 0
            loop
                exitwhen i > 8
                call TriggerAddCondition(trigger[i], Condition(function thistype.onPress))
                set i = i + 1
            endloop
        endmethod
 
Top