DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
input.c
Go to the documentation of this file.
1
3{
7};
8
9//-----------------------------------------------------------------------------
10class Input
11{
12 // input locking
13
20 proto native void ChangeGameFocus(int add, int input_device = -1);
21
27 proto native void ResetGameFocus(int input_device = -1);
28
34 proto native bool HasGameFocus(int input_device = -1);
35
36 // actions
37 proto native int GetActionGroupsCount();
38 proto native int GetActionGroupSize(int group_index);
39 proto int GetActionGroupName(int group_index, out string name);
40 proto int GetActionDesc(int action_index, out string desc);
41
42 // getting action state
50 proto native float LocalValue_ID(int action, bool check_focus = true);
51 proto native float LocalValue(string action, bool check_focus = true);
52
61 proto native bool LocalPress_ID(int action, bool check_focus = true);
62 proto native bool LocalPress(string action, bool check_focus = true);
63
71 proto native bool LocalRelease_ID(int action, bool check_focus = true);
72 proto native bool LocalRelease(string action, bool check_focus = true);
73
81 proto native bool LocalHold_ID(int action, bool check_focus = true);
82 proto native bool LocalHold(string action, bool check_focus = true);
83
91 proto native bool LocalDbl_ID(int action, bool check_focus = true);
92 proto native bool LocalDbl(string action, bool check_focus = true);
93
101 proto native void DisableKey(int key);
102
104 proto native void EnableMouseAndKeyboard(bool enable);
106 proto native bool IsEnabledMouseAndKeyboard();
112
117 proto native bool IsMouseConnected();
118 proto native bool IsKeyboardConnected();
119
121 proto native int GetCurrentProfile();
122 // gets currently selected profile keys for action
123 proto native void GetCurrentProfileActionKeys(int action_index, out TIntArray keys);
125 proto int GetProfileName(int profile_index, out string name);
127 proto native int GetProfilesCount();
129 proto native int SetProfile(int index);
130
131
132 // devices - joystick only!
133 proto native int GetDevicesCount();
134 proto int GetDeviceName(int device_index, out string name);
135 proto native int IsDeviceXInput(int device_index);
136 proto native int IsDeviceEnabled(int device_index);
137 proto native void SetDeviceEnabled(int device_index, bool enabled);
138
140 proto bool GetGamepadThumbDirection(GamepadButton thumbButton, out float angle, out float value);
141
143 proto native void ResetActiveGamepad();
144 proto native void SelectActiveGamepad(int gamepad);
145 proto native void GetGamepadList(out array<int> gamepads);
146 proto void GetGamepadUser(int gamepad, out BiosUser user);
151 proto native void IdentifyGamepad(GamepadButton button);
153 proto native bool IsActiveGamepadSelected();
154
157 {
159 }
160
165 bool AreAllAllowedInputDevicesActive(out array<int> unavailableDeviceList = null)
166 {
167 bool passed = true;
168 bool gamepad = IsActiveGamepadSelected();
169 bool mouse = IsMouseConnected();
170 bool keyboard = IsKeyboardConnected();
171 bool MnKEnabled;
172
173 if (g_Game.GetGameState() != DayZGameState.IN_GAME)
174 {
175 MnKEnabled = IsEnabledMouseAndKeyboard();
176 }
177 else if (g_Game.GetGameState() != DayZGameState.MAIN_MENU)
178 {
180 }
181 else
182 {
183 return true;
184 }
185
186 if (!MnKEnabled)
187 {
188 if (!gamepad)
189 {
190 passed = false;
191 FillUnavailableDeviceArray(EUAINPUT_DEVICE_CONTROLLER,unavailableDeviceList);
192 }
193 }
194 else
195 {
196 if (!gamepad)
197 {
198 if (!mouse)
199 {
200 passed = false;
201 FillUnavailableDeviceArray(EUAINPUT_DEVICE_MOUSE,unavailableDeviceList);
202 }
203 if (!keyboard)
204 {
205 passed = false;
206 FillUnavailableDeviceArray(EUAINPUT_DEVICE_KEYBOARD,unavailableDeviceList);
207 }
208
209 if (!passed)
210 {
211 FillUnavailableDeviceArray(EUAINPUT_DEVICE_CONTROLLER,unavailableDeviceList);
212 }
213 }
214 }
215 return passed;
216 }
217
218 void FillUnavailableDeviceArray(int device, inout array<int> filler)
219 {
220 if (filler)
221 {
222 filler.Insert(device);
223 }
224 }
225
228 {
229 g_Game.GetConnectedInputDeviceList().Clear();
230
232 g_Game.GetConnectedInputDeviceList().Insert(EUAINPUT_DEVICE_CONTROLLER);
233 if (IsMouseConnected())
234 g_Game.GetConnectedInputDeviceList().Insert(EUAINPUT_DEVICE_MOUSE);
236 g_Game.GetConnectedInputDeviceList().Insert(EUAINPUT_DEVICE_KEYBOARD);
237 }
238
244
251
253 void OnGamepadConnected(int gamepad)
254 {
255 #ifdef PLATFORM_PS4
256 BiosUser user;
257 GetGamepadUser( gamepad, user );
258 if (user && user == GetGame().GetUserManager().GetSelectedUser())
259 {
260 SelectActiveGamepad(gamepad);
261 if (GetGame().GetMission())
262 GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_CONTROLLER); //only for PS, xbox handles it on identification
263 }
264 #endif
265
266 #ifdef PLATFORM_XBOX
267 if (gamepad == g_Game.GetPreviousGamepad())
268 {
269 SelectActiveGamepad(g_Game.GetPreviousGamepad());
270 if (GetGame().GetMission())
271 GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_CONTROLLER); //only for PS, xbox handles it on identification
272 }
273 #endif
274 }
275
277 void OnGamepadDisconnected(int gamepad)
278 {
280 {
282
283 if (!g_Game.IsLoading())
284 {
285 DayZLoadState state = g_Game.GetLoadState();
286 if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
287 {
288 if (GetGame().GetMission())
289 GetGame().GetMission().GetOnInputDeviceDisconnected().Invoke(EUAINPUT_DEVICE_CONTROLLER);
290 }
291 }
292 }
293 }
294
296 void OnGamepadIdentification(int gamepad)
297 {
298 if (gamepad > -1)
299 {
300 DayZLoadState state = g_Game.GetLoadState();
301
303 SelectActiveGamepad(gamepad);
304 g_Game.SelectUser(gamepad);
305 g_Game.SetPreviousGamepad(gamepad);
306 if (state == DayZLoadState.MAIN_MENU_START || state == DayZLoadState.MAIN_MENU_USER_SELECT)
307 {
308 if (GetGame().GetMission())
310 }
311
312 if (GetGame() && GetGame().GetMission() && GetGame().GetMission().GetOnInputDeviceConnected())
313 GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_CONTROLLER);
314 }
315 }
316
318 {
319 array<int> gamepads = new array<int>;
320 GetGamepadList( gamepads );
321 for( int i = 0; i < gamepads.Count(); i++ )
322 {
323 BiosUser user2;
324 GetGamepadUser( gamepads[i], user2 );
325 if( user == user2 )
326 return gamepads[i];
327 }
328 return -1;
329 }
330
331 bool IsInactiveGamepadOrUserSelected( int gamepad = -1 )
332 {
333 #ifdef PLATFORM_XBOX
334 return !IsActiveGamepadSelected();
335 #endif
336 #ifdef PLATFORM_PS4
337 BiosUser user;
338 GetGamepadUser( gamepad, user );
339 return (user == GetGame().GetUserManager().GetSelectedUser());
340 #endif
341 return false;
342 }
343
347 {
349 if (!g_Game.IsLoading() && GetGame().GetMission())
350 {
351 DayZLoadState state = g_Game.GetLoadState();
352 if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
353 {
354 GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_MOUSE);
355 }
356 }
357 }
358
362 {
364 if (!g_Game.IsLoading() && GetGame().GetMission())
365 {
366 DayZLoadState state = g_Game.GetLoadState();
367 if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
368 {
369 GetGame().GetMission().GetOnInputDeviceDisconnected().Invoke(EUAINPUT_DEVICE_MOUSE);
370 }
371 }
372 }
373
377 {
379 if (!g_Game.IsLoading() && GetGame().GetMission())
380 {
381 DayZLoadState state = g_Game.GetLoadState();
382 if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
383 {
384 GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_KEYBOARD);
385 }
386 }
387 }
388
392 {
394 if (!g_Game.IsLoading() && GetGame().GetMission())
395 {
396 DayZLoadState state = g_Game.GetLoadState();
397 if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
398 {
399 GetGame().GetMission().GetOnInputDeviceDisconnected().Invoke(EUAINPUT_DEVICE_KEYBOARD);
400 }
401 }
402 }
403
406 {
407 if (GetGame().GetMission())
408 {
410 }
411 }
412};
413
DayZGame g_Game
Definition DayZGame.c:3654
string name
proto native Mission GetMission()
Definition input.c:11
void OnGamepadIdentification(int gamepad)
callback that is fired when identification was requested
Definition input.c:296
proto native int GetActionGroupSize(int group_index)
void OnKeyboardConnected()
Definition input.c:376
proto native void ChangeGameFocus(int add, int input_device=-1)
Change game focus number.
bool AreAllAllowedInputDevicesActive(out array< int > unavailableDeviceList=null)
returns true if 'Gamepad' or if 'Mouse/Keyboard' control is allowed locally and on server,...
Definition input.c:165
bool IsAnyInputDeviceActive()
returns true if 'Gamepad' or 'Mouse and Keyboard' is connected
Definition input.c:156
proto native int GetCurrentProfile()
gets currently selected profile
proto native bool LocalPress_ID(int action, bool check_focus=true)
Returns true just in frame, when action was invoked (button was pressed)
void OnKeyboardDisconnected()
Definition input.c:391
proto native int GetDevicesCount()
void OnMouseDisconnected()
Definition input.c:361
proto native bool LocalHold_ID(int action, bool check_focus=true)
Returns true just in frame, when hold action invoked (button is hold)
proto int GetActionGroupName(int group_index, out string name)
proto native GamepadButton GetEnterButton()
proto native void EnableMouseAndKeyboard(bool enable)
Enable mouse and keyboard (on consoles)
proto native void DisableKey(int key)
Disable key until end of frame.
proto native bool LocalPress(string action, bool check_focus=true)
proto native void GetGamepadList(out array< int > gamepads)
proto int GetActionDesc(int action_index, out string desc)
proto int GetProfileName(int profile_index, out string name)
gets profile by index
void OnGamepadDisconnected(int gamepad)
callback that is fired when gamepad is disconnected
Definition input.c:277
proto native void SetDeviceEnabled(int device_index, bool enabled)
proto native int GetActionGroupsCount()
proto native float LocalValue(string action, bool check_focus=true)
void UpdateConnectedInputDeviceList()
currently lists only available Gamepad, Mouse, and Keyboard. Extendable as needed.
Definition input.c:227
proto native bool LocalDbl_ID(int action, bool check_focus=true)
Returns true just in frame, when double click action invoked (button double clicked)
proto native void SelectActiveGamepad(int gamepad)
proto int GetDeviceName(int device_index, out string name)
int GetUserGamepad(BiosUser user)
Definition input.c:317
proto bool GetGamepadThumbDirection(GamepadButton thumbButton, out float angle, out float value)
return true if was deflected button.
proto native int GetProfilesCount()
gets profile by name
proto native int IsDeviceEnabled(int device_index)
proto void GetGamepadUser(int gamepad, out BiosUser user)
void OnMouseConnected()
Definition input.c:346
proto native bool IsMouseConnected()
proto native bool IsKeyboardConnected()
proto native void GetCurrentProfileActionKeys(int action_index, out TIntArray keys)
bool IsInactiveGamepadOrUserSelected(int gamepad=-1)
Definition input.c:331
proto native void IdentifyGamepad(GamepadButton button)
the on OnGamepadIdentification callback will return the first gamepad where the button was pressed
void OnLastInputDeviceChanged(EInputDeviceType inputDevice)
called from code on different input device use
Definition input.c:405
proto native int SetProfile(int index)
setting active profile
void FillUnavailableDeviceArray(int device, inout array< int > filler)
Definition input.c:218
proto native EInputDeviceType GetCurrentInputDevice()
void OnGamepadConnected(int gamepad)
callback that is fired when a new gamepad is connected
Definition input.c:253
proto native bool LocalHold(string action, bool check_focus=true)
proto native float LocalValue_ID(int action, bool check_focus=true)
Get action state.
proto native bool IsEnabledMouseAndKeyboardEvenOnServer()
proto native bool LocalDbl(string action, bool check_focus=true)
proto native bool IsEnabledMouseAndKeyboard()
proto native void ResetActiveGamepad()
clears active gamepad
proto native int IsDeviceXInput(int device_index)
proto native void ResetGameFocus(int input_device=-1)
Reset game focus number (set to 0)
proto native bool HasGameFocus(int input_device=-1)
Check if game should have focus.
proto native bool IsActiveGamepadSelected()
returns true if there is an active gamepad selected.
proto native bool LocalRelease(string action, bool check_focus=true)
proto native bool LocalRelease_ID(int action, bool check_focus=true)
Returns true just in frame, when release action happened (button was released)
void Reset()
Definition gameplay.c:693
ScriptInvoker GetOnInputDeviceConnected()
Definition gameplay.c:843
ScriptInvoker GetOnInputDeviceDisconnected()
Definition gameplay.c:853
ScriptInvoker GetOnInputDeviceChanged()
Definition gameplay.c:823
proto void Invoke(void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
invoke call on all inserted methods with given arguments
proto native CGame GetGame()
GamepadButton
Definition EnSystem.c:341
EInputDeviceType
Definition input.c:3
@ CONTROLLER
Definition input.c:6
@ UNKNOWN
Definition input.c:4
@ MOUSE_AND_KEYBOARD
Definition input.c:5