How do I convert this AHK script to Titan Two?

Gtuner IV general support. Operation, questions, updates, feature request.

How do I convert this AHK script to Titan Two?

Postby dognose » Thu Dec 06, 2018 8:02 am

#Include %A_AppData%\XIM Link\ScriptAdditionals\AHK_ADDITIONALS.ahk
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

First_Key = 2
Second_Key = 3
Toggle_Key = 1

Hotkey, ~*%Toggle_Key% , Quick_Macro

Quick_Macro:
if (toggle=0)
{
SendInput {%First_Key% down}
sleep 40
SendInput {%First_Key% up}
toggle=1
}
else
{
SendInput {%Second_Key% down}
sleep 40
SendInput {%Second_Key% up}
toggle=0
}
return
User avatar
dognose
Master Sergeant
Master Sergeant
 
Posts: 30
Joined: Sun Nov 11, 2018 8:12 am
Location: South Los Angeles, CA

Re: How do I convert this AHK script to Titan Two?

Postby Scachi » Thu Dec 06, 2018 8:47 am

This will work only if you have the keyboard plugged into the T2 directly or using kmg capture.
No clue about ahk so this gpc2 code migth be doing something different than your ahk script

Code: Select all
#include <keyboard.gph>
 
#define HotKey      KEY_E // key to hold down to run the combo
 
#define Toggle_Key  KEY_1 // key to press to toggle with button the combo presses
 
#define First_Btn   BUTTON_5 // for !toggle rapid press this button
#define Second_Btn  BUTTON_6 // for toggle  rapid press this button
 
 
bool ToggleKeyPressed=FALSE;
bool Toggle=FALSE;
uint8 RapidBtn=First_Btn;
 
main { 
 
    // when key is not active:  reset Pressed flag to allow toggle again
    if (!key_status(Toggle_Key)) ToggleKeyPressed=FALSE;
 
    if (key_status(Toggle_Key) && !ToggleKeyPressed) { // key event_active like
      Toggle = !Toggle;                // invert flag
      if (!Toggle) RapidBtn=First_Btn; // set button to press when Toggle is FALSE
      else RapidBtn=Second_Btn;        // set button to press when Toggle is TRUE
      ToggleKeyPressed=TRUE;           // block toggling again until release / key event_active like
      printf("Toggle: %d",Toggle); // debug output
    }
 
    if (key_status(HotKey)) {
      combo_run(cBtnRapid);
    }
}
 
 
combo cBtnRapid {
  set_val(RapidBtn,100);
  wait(40); // hold down button for 40ms
  set_val(RapidBtn,0);
  wait(40); // release button for 40ms
}
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: How do I convert this AHK script to Titan Two?

Postby dognose » Thu Dec 06, 2018 12:00 pm

Scachi wrote:This will work only if you have the keyboard plugged into the T2 directly or using kmg capture.
No clue about ahk so this gpc2 code migth be doing something different than your ahk script

Code: Select all
#include <keyboard.gph>
 
#define HotKey      KEY_E // key to hold down to run the combo
 
#define Toggle_Key  KEY_1 // key to press to toggle with button the combo presses
 
#define First_Btn   BUTTON_5 // for !toggle rapid press this button
#define Second_Btn  BUTTON_6 // for toggle  rapid press this button
 
 
bool ToggleKeyPressed=FALSE;
bool Toggle=FALSE;
uint8 RapidBtn=First_Btn;
 
main { 
 
    // when key is not active:  reset Pressed flag to allow toggle again
    if (!key_status(Toggle_Key)) ToggleKeyPressed=FALSE;
 
    if (key_status(Toggle_Key) && !ToggleKeyPressed) { // key event_active like
      Toggle = !Toggle;                // invert flag
      if (!Toggle) RapidBtn=First_Btn; // set button to press when Toggle is FALSE
      else RapidBtn=Second_Btn;        // set button to press when Toggle is TRUE
      ToggleKeyPressed=TRUE;           // block toggling again until release / key event_active like
      printf("Toggle: %d",Toggle); // debug output
    }
 
    if (key_status(HotKey)) {
      combo_run(cBtnRapid);
    }
}
 
 
combo cBtnRapid {
  set_val(RapidBtn,100);
  wait(40); // hold down button for 40ms
  set_val(RapidBtn,0);
  wait(40); // release button for 40ms
}


Yes, I am using M+K directly from Titan Two. That script from AHK was to mimic a BF1 like weapon switch. Like on PS4 you press Triangle to switch to primary or secondary weapon. In the game I play you press DPad Left and Right.
User avatar
dognose
Master Sergeant
Master Sergeant
 
Posts: 30
Joined: Sun Nov 11, 2018 8:12 am
Location: South Los Angeles, CA

Re: How do I convert this AHK script to Titan Two?

Postby Scachi » Thu Dec 06, 2018 1:31 pm

This code will press dpad-left or dpad-right once when you press Key_1 to toggle:

Code: Select all
 
#include <keyboard.gph>
 
#define Toggle_Key  KEY_1 // key to press -> changes button the combo presses and starts the combo
 
#define First_Btn   BUTTON_12
#define Second_Btn  BUTTON_13
 
bool ToggleKeyPressed=FALSE;
uint8 WeaponBtn=First_Btn;
 
main { 
 
    // when key is not active:  reset Pressed flag to allow toggle again
    if (!key_status(Toggle_Key)) ToggleKeyPressed=FALSE;
 
    // key event_active like
    if (key_status(Toggle_Key) && !ToggleKeyPressed) {
      ToggleKeyPressed=TRUE;           // block toggling again until release / key event_active like
 
      if (WeaponBtn==First_Btn) WeaponBtn=Second_Btn; // change the button to press
      else WeaponBtn=First_Btn;
 
      printf("Key pressed -> combo started to press Button_%d",WeaponBtn+1); // debug output
      combo_run(cToggle);
    }
}
 
 
combo cToggle {
  set_val(WeaponBtn,100); wait(40); // hold down button for 40ms
  set_val(WeaponBtn,0); wait(40); // release button for 40ms
}
 
 


Output panel output:
Code: Select all
 
GVM Output: Key pressed -> combo started to press Button_13
GVM Output: Key pressed -> combo started to press Button_12
 
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany


Return to Gtuner IV Support

Who is online

Users browsing this forum: No registered users and 73 guests