• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[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