GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2015-11-24 11:12:23

lostdarkwolf
Member
Registered: 2015-11-19
Posts: 31

3 input detection and configuration scripts.

a few very flexible scripts that make user interface configuration and detection a lot easier.

Expand///input_check_button(button)
//
// returns a button's state, real (normalized or bool).
//
// button   what button to check... see key below.
//
/// GMLscripts.com/license

/*****************************\
| BUTTON VALUES:              |
| 1-255   key codes           |  <== mouse clicks are in the key codes. (1 = left, 2 = right, 4 = middle, 5 = back, 6 = foreward)
| 256-257 mouse wheel         |
| 258-265 joystick 1 dpad     |
| 266-297 joystick 1 buttons  |
| 298-309 joystick 1 axes     |  <== axes values are the only values that are normalized
| 310-317 joystick 2 dpad     |
| 318-349 joystick 2 buttons  |
| 350-361 joystick 2 axes     |  <== axes values are the only values that are normalized
\*****************************/
//gamepad values dont seem to work for me; otherwise, they'd be in here too.

if argument[0]<=0 return 0;
if argument[0]<=255 return keyboard_check_direct(argument[0])
if argument[0]=256 return mouse_wheel_up()
if argument[0]=257 return mouse_wheel_down()

if argument[0]=258 return (joystick_pov(1)==225)
if argument[0]=259 return (joystick_pov(1)==270)
if argument[0]=260 return (joystick_pov(1)==315)
if argument[0]=261 return (joystick_pov(1)==180)
if argument[0]=262 return (joystick_pov(1)==0)
if argument[0]=263 return (joystick_pov(1)==135)
if argument[0]=264 return (joystick_pov(1)==90)
if argument[0]=265 return (joystick_pov(1)==45)
if argument[0]>=266 and argument[0]<=265+joystick_buttons(1) return joystick_check_button(1,argument[0]-265);
if argument[0]=298 return min(min(joystick_xpos(1),0),1)
if argument[0]=299 return min(-max(joystick_xpos(1),0),1)
if argument[0]=300 return min(min(joystick_ypos(1),0),1)
if argument[0]=301 return min(-max(joystick_ypos(1),0),1)
if argument[0]=302 return min(min(joystick_zpos(1),0),1)
if argument[0]=303 return min(-max(joystick_zpos(1),0),1)
if argument[0]=304 return min(min(joystick_rpos(1),0),1)
if argument[0]=305 return min(-max(joystick_rpos(1),0),1)
if argument[0]=306 return min(min(joystick_upos(1),0),1)
if argument[0]=307 return min(-max(joystick_upos(1),0),1)
if argument[0]=308 return min(min(joystick_vpos(1),0),1)
if argument[0]=309 return min(-max(joystick_vpos(1),0),1)


if argument[0]=310 return (joystick_pov(2)==225)
if argument[0]=311 return (joystick_pov(2)==270)
if argument[0]=312 return (joystick_pov(2)==315)
if argument[0]=313 return (joystick_pov(2)==180)
if argument[0]=314 return (joystick_pov(2)==0)
if argument[0]=315 return (joystick_pov(2)==135)
if argument[0]=316 return (joystick_pov(2)==90)
if argument[0]=317 return (joystick_pov(2)==45)
if argument[0]>=318 and argument[0]<=317+joystick_buttons(2) return joystick_check_button(2,argument[0]-316);
if argument[0]=350 return min(min(joystick_xpos(2),0),1)
if argument[0]=351 return min(-max(joystick_xpos(2),0),1)
if argument[0]=352 return min(min(joystick_ypos(2),0),1)
if argument[0]=353 return min(-max(joystick_ypos(2),0),1)
if argument[0]=354 return min(min(joystick_zpos(2),0),1)
if argument[0]=355 return min(-max(joystick_zpos(2),0),1)
if argument[0]=356 return min(min(joystick_rpos(2),0),1)
if argument[0]=357 return min(-max(joystick_rpos(2),0),1)
if argument[0]=358 return min(min(joystick_upos(2),0),1)
if argument[0]=359 return min(-max(joystick_upos(2),0),1)
if argument[0]=360 return min(min(joystick_vpos(2),0),1)
if argument[0]=361 return min(-max(joystick_vpos(2),0),1)
Expand///input_find_button()
//
// this will return the currently used input (if there is only one)
// otherwise, it will return -1 or 0. (see key below)
//
// use this script to get an input while re-configuring game controls.
//
/// GMLscripts.com/license

/*****************************\
| RETURN VALUES:              |
| -1      conflict error      |
| 0       none                |
| 1-255   key codes           |  <== mouse clicks are in the key codes. (1 = left, 2 = right, 4 = middle, 5 = back, 6 = foreward)
| 256-257 mouse wheel         |
| 258-265 joystick 1 dpad     |
| 266-297 joystick 1 buttons  |
| 298-309 joystick 1 axes     |
| 310-317 joystick 2 dpad     |
| 318-349 joystick 2 buttons  |
| 350-361 joystick 2 axes     |
\*****************************/
//gamepad values dont seem to work for me; otherwise, they'd be in here too.

var _retty, ii, iideadzone;
_retty=0;
iideadzone=0.8; // a big deadzone is good to avoid getting -1 returned from getting multiple axes values.

//keyboard
for (ii=1; ii<=255; ii++;) if keyboard_check_direct(ii) {if _retty=0 _retty = ii else {if ii!=vk_lcontrol and  ii!=vk_rcontrol and ii!=vk_lalt and ii!=vk_ralt and ii!=vk_lshift and ii!=vk_rshift _retty=-1 else _retty=ii;}};

if mouse_wheel_up() {
 if _retty=0 _retty = 256
 else _retty=-1
}

if mouse_wheel_down() {
 if _retty=0 _retty = 257
 else _retty=-1
}


if joystick_exists(1) {
switch (joystick_pov(1)) {//dpad
    case 225:
     if _retty=0 _retty = 258
     else _retty=-1
    break;
    case 270:
     if _retty=0 _retty = 259
     else _retty=-1
    break;
    case 315:
     if _retty=0 _retty = 260
     else _retty=-1
    break;
    case 180:
     if _retty=0 _retty = 261
     else _retty=-1
    break;
    case 0:
     if _retty=0 _retty = 262
     else _retty=-1
    break;
    case 135:
     if _retty=0 _retty = 263
     else _retty=-1
    break;
    case 90:
     if _retty=0 _retty = 264
     else _retty=-1
    break;
    case 45:
     if _retty=0 _retty = 265
     else _retty=-1
    break;
}

for (ii=1; ii<=joystick_buttons(1); ii++;) {
 if joystick_check_button(1,ii) {
  if _retty=0 _retty = 265+ii
  else _retty=-1
 }
}

//for an axes to trigger, 
//   it cannot be any value within the deadzone.

//x
if joystick_xpos(1)>iideadzone and joystick_axes(1)>=1 {
  if _retty=0 _retty = 298
  else _retty=-1
}
if joystick_xpos(1)<-iideadzone and joystick_axes(1)>=1 {
  if _retty=0 _retty = 299
  else _retty=-1
}
//y
if joystick_ypos(1)>iideadzone and joystick_axes(1)>=2 {
  if _retty=0 _retty = 300
  else _retty=-1
}
if joystick_ypos(1)<-iideadzone and joystick_axes(1)>=2 {
  if _retty=0 _retty = 301
  else _retty=-1
}
//z
if joystick_zpos(1)>iideadzone and joystick_axes(1)>=3 {
  if _retty=0 _retty = 302
  else _retty=-1
}
if joystick_zpos(1)<-iideadzone and joystick_axes(1)>=3 {
  if _retty=0 _retty = 303
  else _retty=-1
}
//r
if joystick_rpos(1)>iideadzone and joystick_axes(1)>=4 {
  if _retty=0 _retty = 304
  else _retty=-1
}
if joystick_rpos(1)<-iideadzone and joystick_axes(1)>=4 {
  if _retty=0 _retty = 305
  else _retty=-1
}
//u
if joystick_upos(1)>iideadzone and joystick_axes(1)>=5 {
  if _retty=0 _retty = 306
  else _retty=-1
}
if joystick_upos(1)<-iideadzone and joystick_axes(1)>=5 {
  if _retty=0 _retty = 307
  else _retty=-1
}
//v
if joystick_vpos(1)>iideadzone and joystick_axes(1)>=6 {
  if _retty=0 _retty = 308
  else _retty=-1
}
if joystick_vpos(1)<-iideadzone and joystick_axes(1)>=6 {
  if _retty=0 _retty = 309
  else _retty=-1
}
}

if joystick_exists(2) {
switch (joystick_pov(2)) {//dpad
    case 225:
     if _retty=0 _retty = 310
     else _retty=-1
    break;
    case 270:
     if _retty=0 _retty = 311
     else _retty=-1
    break;
    case 315:
     if _retty=0 _retty = 312
     else _retty=-1
    break;
    case 180:
     if _retty=0 _retty = 313
     else _retty=-1
    break;
    case 0:
     if _retty=0 _retty = 314
     else _retty=-1
    break;
    case 135:
     if _retty=0 _retty = 315
     else _retty=-1
    break;
    case 90:
     if _retty=0 _retty = 316
     else _retty=-1
    break;
    case 45:
     if _retty=0 _retty = 317
     else _retty=-1
    break;
}

for (ii=1; ii<=joystick_buttons(2); ii++;) {
 if joystick_check_button(2,ii) {
  if _retty=0 _retty = 317+ii
  else _retty=-1
 }
}

//axes
//x
if joystick_xpos(2)>iideadzone and joystick_axes(2)>=1 {
  if _retty=0 _retty = 350
  else _retty=-1
}
if joystick_xpos(2)<-iideadzone and joystick_axes(2)>=1 {
  if _retty=0 _retty = 351
  else _retty=-1
}
//y
if joystick_ypos(2)>iideadzone and joystick_axes(2)>=2 {
  if _retty=0 _retty = 352
  else _retty=-1
}
if joystick_ypos(2)<-iideadzone and joystick_axes(2)>=2 {
  if _retty=0 _retty = 353
  else _retty=-1
}
//z
if joystick_zpos(2)>iideadzone and joystick_axes(2)>=3 {
  if _retty=0 _retty = 354
  else _retty=-1
}
if joystick_zpos(2)<-iideadzone and joystick_axes(2)>=3 {
  if _retty=0 _retty = 355
  else _retty=-1
}
//r
if joystick_rpos(2)>iideadzone and joystick_axes(2)>=4 {
  if _retty=0 _retty = 356
  else _retty=-1
}
if joystick_rpos(2)<-iideadzone and joystick_axes(2)>=4 {
  if _retty=0 _retty = 357
  else _retty=-1
}
//u
if joystick_upos(2)>iideadzone and joystick_axes(2)>=5 {
  if _retty=0 _retty = 358
  else _retty=-1
}
if joystick_upos(2)<-iideadzone and joystick_axes(2)>=5 {
  if _retty=0 _retty = 359
  else _retty=-1
}
//v
if joystick_vpos(2)>iideadzone and joystick_axes(2)>=6 {
  if _retty=0 _retty = 360
  else _retty=-1
}
if joystick_vpos(2)<-iideadzone and joystick_axes(2)>=6 {
  if _retty=0 _retty = 361
  else _retty=-1
}

}

return _retty;
Expand///input_name(button)
//
// this will return an input name
//
// button  what button to use (see key below)
//
/// GMLscripts.com/license

/*****************************\
| BUTTON VALUES:              |
| 1-255   key codes           |  <== mouse clicks are in the key codes. (1 = left, 2 = right, 4 = middle, 5 = back, 6 = foreward)
| 256-257 mouse wheel         |
| 258-265 joystick 1 dpad     |
| 266-297 joystick 1 buttons  |
| 298-309 joystick 1 axes     |
| 310-317 joystick 2 dpad     |
| 318-349 joystick 2 buttons  |
| 350-361 joystick 2 axes     |
\*****************************/

switch argument[0] {
 case 1: return "Mouse Left"
 case 2: return "Mouse Right"
 case 3: return "Cancel"
 case 4: return "Mouse Middle"
 case 5: return "Mouse Back (X1)"
 case 6: return "Mouse Foreward (X2)"
 case 8: return "Backspace"
 case 9: return "Tab"
 case 12: return "Clear"
 case 13: return "Enter"
 case 16: return "Shift"
 case 17: return "Control"
 case 18: return "Alt"
 case 19: return "Pause"
 case 20: return "Caps Lock"
 case 21: return "Hangul"
 case 23: return "Junja"
 case 24: return "Final"
 case 25: return "Kanji"
 case 27: return "Escape"
 case 28: return "Convert"
 case 29: return "Nonconvert"
 case 30: return "Accept"
 case 31: return "Mode Change"
 case 32: return "Space"
 case 33: return "Page Up"
 case 34: return "Page Down"
 case 35: return "End"
 case 36: return "Home"
 case 37: return "Left Arrow"
 case 38: return "Up Arrow"
 case 39: return "Right Arrow"
 case 40: return "Down Arrow"
 case 41: return "Select"
 case 42: return "Print"
 case 43: return "Execute"
 case 44: return "Print Screen"
 case 45: return "Insert"
 case 46: return "Delete"
 case 47: return "Help"
 case 48: return "Numberline Zero"
 case 49: return "Numberline One"
 case 50: return "Numberline Two"
 case 51: return "Numberline Three"
 case 52: return "Numberline Four"
 case 53: return "Numberline Five"
 case 54: return "Numberline Six"
 case 55: return "Numberline Seven"
 case 56: return "Numberline Eight"
 case 57: return "Numberline Nine"
 case 65: return "Letter A"
 case 66: return "Letter B"
 case 67: return "Letter C"
 case 68: return "Letter D"
 case 69: return "Letter E"
 case 70: return "Letter F"
 case 71: return "Letter G"
 case 72: return "Letter H"
 case 73: return "Letter I"
 case 74: return "Letter J"
 case 75: return "Letter K"
 case 76: return "Letter L"
 case 77: return "Letter M"
 case 78: return "Letter N"
 case 79: return "Letter O"
 case 80: return "Letter P"
 case 81: return "Letter Q"
 case 82: return "Letter R"
 case 83: return "Letter S"
 case 84: return "Letter T"
 case 85: return "Letter U"
 case 86: return "Letter V"
 case 87: return "Letter W"
 case 88: return "Letter X"
 case 89: return "Letter Y"
 case 90: return "Letter Z"
 case 91: return "Windows (left)"
 case 92: return "Windows (right)"
 case 93: return "Apps"
 case 95: return "Sleep"
 case 96: return "Numberpad Zero"
 case 97: return "Numberpad One"
 case 98: return "Numberpad Two"
 case 99: return "Numberpad Three"
 case 100: return "Numberpad Four"
 case 101: return "Numberpad Five"
 case 102: return "Numberpad Six"
 case 103: return "Numberpad Seven"
 case 104: return "Numberpad Eight"
 case 105: return "Numberpad Nine"
 case 106: return "Numberpad Multiply"
 case 107: return "Numberpad Add"
 case 108: return "Numberpad Subtract"
 case 109: return "Subtract"
 case 110: return "Decimal"
 case 111: return "Divide"
 case 112: return "F1"
 case 113: return "F2"
 case 114: return "F3"
 case 115: return "F4"
 case 116: return "F5"
 case 117: return "F6"
 case 118: return "F7"
 case 119: return "F8"
 case 120: return "F9"
 case 121: return "F10"
 case 122: return "F11"
 case 123: return "F12"
 case 124: return "F13"
 case 125: return "F14"
 case 126: return "F15"
 case 127: return "F16"
 case 128: return "F17"
 case 129: return "F18"
 case 130: return "F19"
 case 131: return "F20"
 case 132: return "F21"
 case 133: return "F22"
 case 134: return "F23"
 case 135: return "F24"
 case 144: return "Number Lock"
 case 145: return "Scroll Lock"
 case 160: return "Shift (Left)"
 case 161: return "Shift (Right)"
 case 162: return "Control (Left)"
 case 163: return "Control (Right)"
 case 164: return "Alt (Left)"
 case 165: return "Alt (Right)"
 case 166: return "Back"
 case 167: return "Foreward"
 case 168: return "Refresh"
 case 169: return "Stop"
 case 170: return "Search"
 case 171: return "Favorites"
 case 172: return "Browser"
 case 173: return "Mute"
 case 174: return "Volume Down"
 case 175: return "Volume Up"
 case 176: return "Next Track"
 case 177: return "Previous Track"
 case 178: return "Stop Trak"
 case 179: return "Play Track"
 case 180: return "Mail"
 case 181: return "Media"
 case 182: return "Application 1"
 case 183: return "Application 2"
 case 186: return "Semicolon"
 case 187: return "Equals"
 case 188: return "Comma"
 case 189: return "Dash"
 case 190: return "Period"
 case 191: return "Foreward Slash"
 case 192: return "Tilde"
 case 219: return "Left Bracket"
 case 220: return "Backslash"
 case 221: return "Right Bracket"
 case 222: return "Apostrophe"
 case 229: return "Process"
 case 231: return "Packet"
 case 246: return "Attn"
 case 247: return "CrSel"
 case 248: return "ExSel"
 case 249: return "Erase EOF"
 case 250: return "Play"
 case 251: return "Zoom"
 case 253: return "PA1"
 case 254: return "Clear"
 // is there a 255? I dont know but probably not.
 case 256: return "Mouse Wheel Up"
 case 257: return "Mouse Wheel Down"
 case 258: return "Hat Left-Down (Pad 1)"
 case 259: return "Hat Left (Pad 1)"
 case 260: return "Hat Left-Up (Pad 1)"
 case 261: return "Hat Down (Pad 1)"
 case 262: return "Hat Up (Pad 1)"
 case 263: return "Hat Right-Down (Pad 1)"
 case 264: return "Hat Right (Pad 1)"
 case 265: return "Hat Right-Up (Pad 1)"
 case 266: return "Button 1 (Pad 1)"
 case 267: return "Button 2 (Pad 1)"
 case 268: return "Button 3 (Pad 1)"
 case 269: return "Button 4 (Pad 1)"
 case 270: return "Button 5 (Pad 1)"
 case 271: return "Button 6 (Pad 1)"
 case 272: return "Button 7 (Pad 1)"
 case 273: return "Button 8 (Pad 1)"
 case 274: return "Button 9 (Pad 1)"
 case 275: return "Button 10 (Pad 1)"
 case 276: return "Button 11 (Pad 1)"
 case 277: return "Button 12 (Pad 1)"
 case 278: return "Button 13 (Pad 1)"
 case 279: return "Button 14 (Pad 1)"
 case 280: return "Button 15 (Pad 1)"
 case 281: return "Button 16 (Pad 1)"
 case 282: return "Button 17 (Pad 1)"
 case 283: return "Button 18 (Pad 1)"
 case 284: return "Button 19 (Pad 1)"
 case 285: return "Button 20 (Pad 1)"
 case 286: return "Button 21 (Pad 1)"
 case 287: return "Button 22 (Pad 1)"
 case 288: return "Button 23 (Pad 1)"
 case 289: return "Button 24 (Pad 1)"
 case 290: return "Button 25 (Pad 1)"
 case 291: return "Button 26 (Pad 1)"
 case 292: return "Button 27 (Pad 1)"
 case 293: return "Button 28 (Pad 1)"
 case 294: return "Button 29 (Pad 1)"
 case 295: return "Button 30 (Pad 1)"
 case 296: return "Button 31 (Pad 1)"
 case 297: return "Button 32 (Pad 1)"
 
 case 298: return "X-Axis + (Pad 1)"
 case 299: return "X-Axis - (Pad 1)"
 case 300: return "Y-Axis + (Pad 1)"
 case 301: return "Y-Axis - (Pad 1)"
 case 302: return "Z-Axis + (Pad 1)"
 case 303: return "Z-Axis - (Pad 1)"
 case 304: return "R-Axis + (Pad 1)"
 case 305: return "R-Axis - (Pad 1)"
 case 306: return "U-Axis + (Pad 1)"
 case 307: return "U-Axis - (Pad 1)"
 case 308: return "V-Axis + (Pad 1)"
 case 309: return "V-Axis - (Pad 1)"

 case 310: return "Hat Left-Down (Pad 2)"
 case 311: return "Hat Left (Pad 2)"
 case 312: return "Hat Left-Up (Pad 2)"
 case 313: return "Hat Down (Pad 2)"
 case 314: return "Hat Up (Pad 2)"
 case 315: return "Hat Right-Down (Pad 2)"
 case 316: return "Hat Right (Pad 2)"
 case 317: return "Hat Right-Up (Pad 2)"
 case 318: return "Button 1 (Pad 2)"
 case 319: return "Button 2 (Pad 2)"
 case 320: return "Button 3 (Pad 2)"
 case 321: return "Button 4 (Pad 2)"
 case 322: return "Button 5 (Pad 2)"
 case 323: return "Button 6 (Pad 2)"
 case 324: return "Button 7 (Pad 2)"
 case 325: return "Button 8 (Pad 2)"
 case 326: return "Button 9 (Pad 2)"
 case 327: return "Button 10 (Pad 2)"
 case 328: return "Button 11 (Pad 2)"
 case 329: return "Button 12 (Pad 2)"
 case 330: return "Button 13 (Pad 2)"
 case 331: return "Button 14 (Pad 2)"
 case 332: return "Button 15 (Pad 2)"
 case 333: return "Button 16 (Pad 2)"
 case 334: return "Button 17 (Pad 2)"
 case 335: return "Button 18 (Pad 2)"
 case 336: return "Button 19 (Pad 2)"
 case 337: return "Button 20 (Pad 2)"
 case 338: return "Button 21 (Pad 2)"
 case 339: return "Button 22 (Pad 2)"
 case 340: return "Button 23 (Pad 2)"
 case 341: return "Button 24 (Pad 2)"
 case 342: return "Button 25 (Pad 2)"
 case 343: return "Button 26 (Pad 2)"
 case 344: return "Button 27 (Pad 2)"
 case 345: return "Button 28 (Pad 2)"
 case 346: return "Button 29 (Pad 2)"
 case 347: return "Button 30 (Pad 2)"
 case 348: return "Button 31 (Pad 2)"
 case 349: return "Button 32 (Pad 2)"

 case 350: return "X-Axis + (Pad 2)"
 case 351: return "X-Axis - (Pad 2)"
 case 352: return "Y-Axis + (Pad 2)"
 case 353: return "Y-Axis - (Pad 2)"
 case 354: return "Z-Axis + (Pad 2)"
 case 355: return "Z-Axis - (Pad 2)"
 case 356: return "R-Axis + (Pad 2)"
 case 357: return "R-Axis - (Pad 2)"
 case 358: return "U-Axis + (Pad 2)"
 case 359: return "U-Axis - (Pad 2)"
 case 360: return "V-Axis + (Pad 2)"
 case 361: return "V-Axis - (Pad 2)"
 
 default: return "Unknown ("+ string(argument[0])+")"
}

Last edited by lostdarkwolf (2018-02-09 02:41:02)

Offline

#2 2015-11-25 00:41:56

xot
Administrator
Registered: 2007-08-18
Posts: 1,240

Re: 3 input detection and configuration scripts.

Interesting script ideas! Couple these with some good macros for the codes and you have a really simple way to get a wide variety of input.


Abusing forum power since 1986.

Offline

Board footer

Powered by FluxBB