Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[New G2O][Client-Side] Key Combination
#1
*Introduction:

NOTE! You have to enable event onRender via enableEvent_Render function

Info: This script is stable and propably doesn't have any bugs.

Hi there, lately i was working on some simple script, which allows to register some key shortcuts in game and i want to share my work.
It's easy to use, for example: you can bind ALT+F4 shortcut to quickly close the game. Also if you want to add combination like:
CTRL+WINDOWS (L_CTRL or R_CTRL) + (L_WINDOWS or R_WINDOWS) you can use string replacements for keys like:
CONTROL, ALT, SHIFT and WINDOWS.

License

Download

*List of functions:



void addKeyCombination(array keys, func callback, [[optional: bool multiple)
void removeKeyCombination(array keys, [[optional: func callback, bool multiple ]])



*List of string replacements: (they're blind to letter capitalization)



"Windows" // This key replacement should be used when you want to add shortcut which is using one of the Windows keys (Left or Right).
"Control" // This key replacement should be used when you want to add shortcut which is using one of the Control keys (Left or Right).
"Ctrl" // This is the alias for "Control".
"Alt" // This key replacement should be used when you want to add shortcut which is using one of the Alt keys (Left or Right).
"Shift" // This key replacement should be used when you want to add shortcut which is using one of the Shift keys (Left or Right).



*Function (addKeyCombination, removeKeyCombination) parameters description:

Info: The more arguments you give in removeKeyCombination function, the more precise you remove bound key shortcut(s).
NOTE! You can skip (set as null) every argument in calling removeKeyCombination function.



// Required parameters for addKeyCombination

array keys // Array of shortcut keys.
void callback // The function which will be called.

// Optional parameters for addKeyCombination

bool multiple /* If this argument is equal true (default is false),
when you hold keys, function will be called more than once. */




*Examples:



*Basic add key shortcut (fast closing game):

Squirrel Script
  1. addKeyCombination([KEY_LMENU,KEY_F4], exitGame)



*Another add key shortcut (with multiple):

Squirrel Script
  1. addKeyCombination(["Ctrl",KEY_S], function()
  2. { // adding LCTRL+S or RCTRL+S combination
  3. print("Spam") // this will pring msg in console (~) and this function will be called more than once when you hold keys.
  4. },true)



*Basic remove key shortcut:

Squirrel Script
  1. // dummy example adding and removing combination
  2. addKeyCombination([KEY_LMENU,KEY_F4], exitGame)
  3. removeKeyCombination([KEY_LMENU,KEY_F4],exitGame)



*Another remove key shortcut:

Squirrel Script
  1. addKeyCombination([KEY_Q,KEY_E],function()
  2. {
  3. print("This msg will be printed only once!") // printing msg in console(~)
  4. removeKeyCombination([KEY_Q,KEY_E]) // removing every combination Q+E
  5. })


Reply
#2
Thread and script have been updated.

Changes:
-Thread has been completely rewritten.
-onRender function has been optimalized (less looping)
-Added string replacements. Example: You have L_Ctrl and R_Ctrl, and let's assume that you want to add one combination like:
L_CTRL+S or R_CTRL+S. To do that simpler you can use string replacements for keys like: Control, Shift, Alt and Windows.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [New G2O][Client] Free Camera Patrix 2 1,758 06.05.2020, 17:53
Last Post: Patrix
  [Client] Version check Quarchodron 2 1,693 25.08.2019, 13:06
Last Post: Quarchodron
  [Client] GUI Creator Quarchodron 6 3,152 12.08.2019, 22:05
Last Post: Arkhan
  [New G2O][Shared] OOP Area Manager Patrix 4 4,562 21.02.2019, 08:35
Last Post: Patrix
  [New G2O][Client-Side] bindKey Patrix 6 4,645 14.11.2018, 01:32
Last Post: Patrix
  [New G2O][Client-Side] OOP Camera Movement Patrix 1 2,144 20.10.2018, 13:22
Last Post: Patrix
  [New G2O][Shared] Command Handler Patrix 3 3,219 05.09.2018, 14:42
Last Post: Patrix
  [New G2O][Shared] packetListener Patrix 3 3,443 20.06.2018, 17:43
Last Post: Tommy
  [0.1.4.*] [client/server] Simple anty-cheat Profesores 8 4,980 20.03.2018, 18:16
Last Post: Patrix
  [0.1.3] [client/server] BotCreator HammelGammel 22 13,184 08.02.2018, 21:02
Last Post: HammelGammel

Forum Jump:


Users browsing this thread: 1 Guest(s)