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


Messages In This Thread
[New G2O][Client-Side] Key Combination - by Patrix - 08.06.2017, 19:22

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Client] Version check Quarchodron 2 4,010 25.08.2019, 14:06
Last Post: Quarchodron
  [Client] GUI Creator Quarchodron 6 7,516 12.08.2019, 23:05
Last Post: Arkhan
  [New G2O][Client-Side] bindKey Patrix 6 8,969 14.11.2018, 02:32
Last Post: Patrix
  [New G2O][Shared] Command Handler Patrix 3 6,171 05.09.2018, 15:42
Last Post: Patrix
  [New G2O][Shared] packetListener Patrix 3 6,653 20.06.2018, 18:43
Last Post: Tommy
  [0.1.4.*] [client/server] Simple anty-cheat Profesores 8 10,244 20.03.2018, 19:16
Last Post: Patrix
  [0.1.3] [client/server] BotCreator HammelGammel 22 26,549 08.02.2018, 22:02
Last Post: HammelGammel
  [0.1.3] [client/server] Utility Scripts HammelGammel 1 5,252 27.01.2018, 14:03
Last Post: HammelGammel
  [G2O v.0.1.2][Server-Side] NPC Manager Quarchodron 16 17,484 21.01.2018, 19:59
Last Post: Quarchodron
  [CLIENT]Draw(Line/Color) Tommy 0 3,118 19.12.2017, 04:23
Last Post: Tommy

Forum Jump:


Users browsing this thread: 1 Guest(s)