![]() |
#1 | |
Two Blue
|
![]()
Introduction
KeyAction is written in vJass and requires the NewGen editor, or Jass Helper in some other configuration. KeyAction requires the latest version of Jass Helper.Credits
The KeyAction Library Requirements: ![]() Change Log
|
|
![]() |
![]() |
Sponsored Links - Login to hide this ad! |
|
![]() |
#2 |
User
Join Date: Mar 2009
Posts: 1,079
![]() ![]() |
![]() Yes very nice,... But I guess there is nothing that removes the delay of arrow keys or?
__________________Anyway, I see very much use in this. For an hero arrow selection system, for example. Still don't get why you use a trigger per arrow and for every arrowstate, instead sharing one and checking the gameevent. ![]() function eventHandler takes nothing returns nothing if EVENT_PLAYER_ARROW_DOWN_UP == GetTriggerEventId() then //Arrow_up_stuff endif endfunction |
![]() |
![]() |
![]() |
#3 | ||
Two Blue
|
![]() Quote:
Using a program like DelayReducer to reduce Battle.net lag will help on battle.net. There is still, however, an intrinsic delay in arrow keys registering events for some unknown reason. Quote:
|
||
![]() |
![]() |
![]() |
#4 | |
User
Join Date: Mar 2009
Posts: 1,079
![]() ![]() |
![]() Quote:
But it doesn't matter at all. Its good, and since I have my own bnet I don't have any delay. |
|
![]() |
![]() |
![]() |
#5 |
User
Join Date: Apr 2008
Posts: 286
![]() |
![]() Hey, nice.
Made this a while ago: ![]() library ArrowkeyController initializer Init globals // A problem with the arrow keys are, that they always have some delay. // Normally it's 0.25 (it's a constant) private constant real ARROW_KEY_REACTION_TIME = 0.25 // The bigger the smoother the 'back camera movement' but the less // the accurarry private constant real CAMERA_SMOOTHING = 1.00 endglobals globals private trigger onArrowKey = CreateTrigger() private trigger releaseArrowKey = CreateTrigger() private boolean array Allowed private boolean array IsLocked private real array CamX private real array CamY endglobals private function unlockCamera takes nothing returns nothing local integer ID = GetPlayerId(GetTriggerPlayer()) local real x local real y if Allowed[ID] then if GetLocalPlayer() == GetTriggerPlayer() then call PanCameraToTimed(CamX[ID], CamY[ID], 0.5) endif set IsLocked[ID] = false endif endfunction private function lockCamera takes nothing returns nothing local integer ID = GetPlayerId(GetTriggerPlayer()) local real x local real y if Allowed[ID] then set IsLocked[ID] = true if GetLocalPlayer() == GetTriggerPlayer() then call PanCameraToTimed(CamX[ID], CamY[ID], ARROW_KEY_REACTION_TIME*CAMERA_SMOOTHING) endif endif endfunction private function SaveCamCoords takes nothing returns nothing local integer i = 0 loop exitwhen i == 12 if IsLocked[i] == false then if GetLocalPlayer() == Player(i) then set CamX[i] = GetCameraTargetPositionX() set CamY[i] = GetCameraTargetPositionY() endif endif set i = i + 1 endloop endfunction private function Init takes nothing returns nothing local integer i = 0 loop exitwhen i == 12 set Allowed[i] = true if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(i)) == MAP_CONTROL_USER then call TriggerRegisterPlayerEvent(onArrowKey, Player(i), EVENT_PLAYER_ARROW_UP_DOWN) call TriggerRegisterPlayerEvent(onArrowKey, Player(i), EVENT_PLAYER_ARROW_DOWN_DOWN) call TriggerRegisterPlayerEvent(onArrowKey, Player(i), EVENT_PLAYER_ARROW_RIGHT_DOWN) call TriggerRegisterPlayerEvent(onArrowKey, Player(i), EVENT_PLAYER_ARROW_LEFT_DOWN) call TriggerRegisterPlayerEvent(releaseArrowKey, Player(i), EVENT_PLAYER_ARROW_UP_UP) call TriggerRegisterPlayerEvent(releaseArrowKey, Player(i), EVENT_PLAYER_ARROW_DOWN_UP) call TriggerRegisterPlayerEvent(releaseArrowKey, Player(i), EVENT_PLAYER_ARROW_RIGHT_UP) call TriggerRegisterPlayerEvent(releaseArrowKey, Player(i), EVENT_PLAYER_ARROW_LEFT_UP) endif set i = i + 1 endloop call TriggerAddAction(onArrowKey,function lockCamera) call TriggerAddAction(releaseArrowKey,function unlockCamera) call TimerStart(CreateTimer(),ARROW_KEY_REACTION_TIME,true,function SaveCamCoords) endfunction public function Allow takes boolean flag returns nothing local integer i = 0 if flag == true then call DisableTrigger(onArrowKey) call DisableTrigger(releaseArrowKey) else loop exitwhen i == 12 call PanCameraToTimed(CamX[i], CamY[i], 0.5) set i = i + 1 endloop call EnableTrigger(onArrowKey) call EnableTrigger(releaseArrowKey) endif endfunction public function AllowFor takes player p, boolean flag returns nothing set Allowed[GetPlayerId(p)] = flag endfunction endlibrary You should add sth. like that to your library. Making movement via arrow keys not possible. But I'm not sure if that fits into a library like that. Niceldy done. |
![]() |
![]() |
![]() |
#6 | |
requires vJass
Code Moderator
|
![]() Quote:
That's the kind of thing that should require a library like this. It would shorten and simplify the code. |
|
![]() |
![]() |
![]() |
#7 |
†6†
Join Date: Oct 2008
Posts: 841
![]() ![]() |
![]() __________________ |
![]() |
![]() |
![]() |
#9 | |
Two Blue
|
![]() Quote:
I like my API better. Also the ability to register multiple callbacks directly to the library. (Limited utility, but useful on rare occasions.) I don't feel like putting work in to improving this much any time soon, so do as you see fit. Let it rot, approve it, graveyard it. (I can always resubmit it in the future) |
|
![]() |
![]() |
![]() |
#10 |
Procrastination Incarnate
Development Director
|
![]() I guess I've spent enough time trying to figure out what to do with this. It is certainly coded with more rigour than ArrowKeys and should probably replace it. However, I don't see anything here that would easily replicate the "quickpress" functionality of ArrowKeys, which is a bit ugly but a very functional hack. On top of that, I suppose some people might prefer a more lightweight library so I guess the two of them can coexist in the resource section, even if that means the number of libraries handling arrow keys will approach the number of people who actually have a use for them.
__________________Approved. |
![]() |
![]() |
![]() |
#11 |
Procrastination Incarnate
Development Director
|
![]() I found a couple of bugs in the OnKeyAction module.
__________________![]() ![]() Edit: there can also be trouble if struct instances are destroyed in the OnKeyAction callback. Not sure what would be the best way to avoid issues here. Last edited by Anitarf : 09-26-2011 at 12:14 PM. |
![]() |
![]() |
![]() |
#12 |
User
Join Date: Jul 2010
Posts: 72
![]() |
![]() this bug doesnt break anything but definitely a bad bug for how easy the fix is...
![]() private function OnInit takes nothing returns nothing local integer i //! textmacro KeyAction_RegisterEvents takes KEY, DIR set i = 0 loop exitwhen i > 11 // The actual event call TriggerRegisterPlayerEvent(key_$KEY$_$DIR$, Player(i), EVENT_PLAYER_ARROW_$KEY$_$DIR$) // For the functions call TriggerAddCondition(key_$KEY$_$DIR$, Condition(function HandleKeyEventFunc_$KEY$_$DIR$)) set i = i + 1 endloop //! endtextmacro //! runtextmacro KeyAction_RegisterEvents("UP", "DOWN") //! runtextmacro KeyAction_RegisterEvents("UP", "UP") //! runtextmacro KeyAction_RegisterEvents("DOWN", "DOWN") //! runtextmacro KeyAction_RegisterEvents("DOWN", "UP") //! runtextmacro KeyAction_RegisterEvents("LEFT", "DOWN") //! runtextmacro KeyAction_RegisterEvents("LEFT", "UP") //! runtextmacro KeyAction_RegisterEvents("RIGHT", "DOWN") //! runtextmacro KeyAction_RegisterEvents("RIGHT", "UP") endfunction should be ![]() private function OnInit takes nothing returns nothing local integer i //! textmacro KeyAction_RegisterEvents takes KEY, DIR set i = 0 loop exitwhen i > 11 // The actual event call TriggerRegisterPlayerEvent(key_$KEY$_$DIR$, Player(i), EVENT_PLAYER_ARROW_$KEY$_$DIR$) set i = i + 1 endloop // For the functions call TriggerAddCondition(key_$KEY$_$DIR$, Condition(function HandleKeyEventFunc_$KEY$_$DIR$)) //! endtextmacro //! runtextmacro KeyAction_RegisterEvents("UP", "DOWN") //! runtextmacro KeyAction_RegisterEvents("UP", "UP") //! runtextmacro KeyAction_RegisterEvents("DOWN", "DOWN") //! runtextmacro KeyAction_RegisterEvents("DOWN", "UP") //! runtextmacro KeyAction_RegisterEvents("LEFT", "DOWN") //! runtextmacro KeyAction_RegisterEvents("LEFT", "UP") //! runtextmacro KeyAction_RegisterEvents("RIGHT", "DOWN") //! runtextmacro KeyAction_RegisterEvents("RIGHT", "UP") endfunction oh yeah it also means that the initial event (where it sets the key down and all that internal magic) happens 12 times, each time the exact same things being set lol also i thought id share my findings after using this. the system works great and allows easy access / general use. id definitely recommend this as a prototyping thing ("hmm... is this actually a good idea?") but if you need to react to quick key presses youll need to either make your own system or butcher out the "general" components of this one. by quickpress, i mean >1 second reaction time AND frequent key presses. you should just use this system barring that Last edited by Yrth : 10-16-2014 at 01:44 AM. |
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
|
|