SemlerPDX

AVCS QCC Get PTT Key or Button v3 for VoiceAttack

Jan 30th, 2021 (edited)
1,202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 21.24 KB | None | 0 0
  1. ' Push to Talk Button Inline-Function for VoiceAttack -  Get/Set any Keyboard/Mouse/Joystick Button as a PTT Button
  2. '  by SemlerPDX Jan2021/Oct2021
  3. '  VETERANS-GAMING.COM
  4.  
  5.  
  6. Imports Microsoft.VisualBasic
  7. Imports System
  8. Imports System.Collections
  9. Imports System.Collections.Generic
  10. Imports System.Threading
  11. Imports System.Threading.Tasks
  12. Imports System.Windows.Forms
  13.  
  14.  
  15. Public Class VAInline
  16.     dim mouseButtons() as string = {
  17.         "STATE_LEFTMOUSEBUTTON",
  18.         "STATE_RIGHTMOUSEBUTTON",
  19.         "STATE_MIDDLEMOUSEBUTTON",
  20.         "STATE_FORWARDMOUSEBUTTON",
  21.         "STATE_BACKMOUSEBUTTON"
  22.     }
  23.     dim gamepadTriggers() as string = {"LEFTTRIGGER","RIGHTTRIGGER"}
  24.    
  25.     dim buttonsAlreadySetList as New List(Of String)
  26.     dim buttonsAlwaysDownList as New List(Of String)
  27.     dim buttonsAlwaysDown as boolean = False
  28.     dim buttonDown as string = ""
  29.     dim buttonCheck as string = ""
  30.     dim checkPOV as string = ""
  31.     dim buttonSet as boolean = False
  32.     dim userReady as boolean = False
  33.     dim counter as integer = 0
  34.    
  35.     dim keyCheck as string = ""
  36.     dim keyString as string = ""
  37.     dim keyCode() as string
  38.    
  39.     dim kc as KeysConverter = new KeysConverter()
  40.    
  41.     dim activeProfile as string = "CORE"
  42.    
  43.     dim debugCheck as boolean
  44.     dim debugCount as integer = 0
  45.    
  46.    
  47.     Private Function SendDebugMessage(ByVal debugText as string, ByVal debugColor as integer)
  48.         '1=Blue - 2=Green - 3=Yellow - 4=Red - 5=Purple - 6=Blank - 7=Orange - 8=Black - 9=Gray - 10=Pink
  49.         if ((VA.GetText("AVCS_Debug_QMSG")) isNot nothing)
  50.             debugCount = VA.GetInt("AVCS_Debug_QMSG")
  51.         end if
  52.         debugCount += 1
  53.         VA.SetText("AVCS_Debug_TMSG_" + debugCount.ToString(), debugText)
  54.         VA.SetInt("AVCS_Debug_WCLR_" + debugCount.ToString(), debugColor)
  55.         VA.SetInt("AVCS_Debug_QMSG", debugCount)
  56.         try
  57.             vaProxy.Command.Execute("f_core_debug -log", true)
  58.         catch
  59.             VA.WriteToLog("AVCS ERROR: PTTGET02 - f_core_debug null - restart VoiceAttack or create bug report", "red")
  60.         end try
  61.         debugCount = 0
  62.     end function
  63.    
  64.     Private Function BuildPTTkeysList()
  65.         for keyIndex as integer = 1 to 6
  66.             'Check for PTT buttons already set
  67.             if ((VA.GetText("AVCS_" + activeProfile + "_PTTBUTTON_" + keyIndex.ToString())) isNot nothing)
  68.                 buttonCheck = VA.GetText("AVCS_" + activeProfile + "_PTTBUTTON_" + keyIndex.ToString())
  69.                 buttonsAlreadySetList.Add(buttonCheck)
  70.             end if
  71.         next
  72.     end function
  73.    
  74.     Private Function BuildAlwaysDownList()
  75.         'Mouse Buttons Baseline State Loop
  76.         if ((vaProxy.Utility.ParseTokens("{STATE_ANYMOUSEDOWN}")) <> "0")
  77.             for m as integer = 0 to 4
  78.                 if ((vaProxy.Utility.ParseTokens("{"+ mouseButtons(m) +"}")) <> "0")
  79.                     buttonsAlwaysDownList.Add(mouseButtons(m))
  80.                     buttonsAlwaysDown = true
  81.                     if (debugCheck)
  82.                         SendDebugMessage("MOUSE BUTTON ("+ mouseButtons(m) +") DISREGARED AS ALWAYS DOWN", 4)
  83.                     end if
  84.                 end if
  85.             next
  86.         end if
  87.        
  88.         'Keyboard Key Baseline State Loop
  89.         for k as integer = 1 to 254
  90.             if ((vaProxy.Utility.ParseTokens("{STATE_ANYKEYDOWN}")) <> "0")
  91.                 if ((vaProxy.Utility.ParseTokens("{STATE_KEYSTATE:" + k.ToString() + "}")) = "1")
  92.                     buttonsAlwaysDownList.Add("STATE_KEYSTATE:" + k.ToString())
  93.                     buttonsAlwaysDown = true
  94.                     if (debugCheck)
  95.                         SendDebugMessage("KEYBOARD KEY (virtual-key code " + k.ToString() + ") DISREGARED AS ALWAYS DOWN", 4)
  96.                     end if
  97.                 end if
  98.             end if
  99.         next
  100.        
  101.         'Joystick Button Baseline State Loop
  102.         for d as integer = 1 to 4
  103.             if ((vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "ENABLED}")) = "1")
  104.                
  105.                 'Joystick Buttons Baseline "Pressed" States
  106.                 if ((vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "ANYBUTTON}")) <> "0")
  107.                     for i as integer = 1 to 128
  108.                         if ((vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "BUTTON:" + i.ToString() + "}")) = "1")
  109.                             buttonsAlwaysDownList.Add("STATE_JOYSTICK" + d.ToString() + "BUTTON:" + i.ToString())
  110.                             buttonsAlwaysDown = true
  111.                             if (debugCheck)
  112.                                 SendDebugMessage("JOYSTICK " + d.ToString() + " BUTTON " + i.ToString() + " DISREGARED - POSSIBLE DUAL STAGE TRIGGER", 4)
  113.                             end if
  114.                         end if
  115.                     next
  116.                     'Joystick POV Buttons Baseline States (4-way only)
  117.                     if ((vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "POVENABLED}")) = "1")
  118.                         for i as integer = 1 to 4
  119.                             if ((vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "POV" + i.ToString() + "TYPE}")) = "4")
  120.                                 'Loop though this Joystick POV 1-4
  121.                                 if ((vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "POV" + i.ToString() + "}")) <> "CENTER")
  122.                                     checkPOV = vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "POV" + i.ToString() + "}")
  123.                                     buttonsAlwaysDownList.Add("STATE_JOYSTICK" + d.ToString() + "POV" + i.ToString() + ":" + checkPOV)
  124.                                     buttonsAlwaysDown = true
  125.                                     if (debugCheck)
  126.                                         SendDebugMessage("JOYSTICK " + d.ToString() + " POV " + i.ToString() + ":" + checkPOV + " DISREGARED", 4)
  127.                                     end if
  128.                                 end if
  129.                             end if
  130.                         next
  131.                     end if
  132.                    
  133.                 end if
  134.                
  135.                 'Joystick as Gamepad Baseline Trigger States (with 20 of 255 as 'deadzone')
  136.                 if ((vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "ISGAMEPAD}")) <> "0")
  137.                     for t as integer = 0 to 1
  138.                         if (IsNumeric(vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + gamepadTriggers(t) + "}")))
  139.                             if ((Convert.ToInt32(vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + gamepadTriggers(t) + "}"))) > 20)
  140.                                 buttonsAlwaysDownList.Add("STATE_JOYSTICK" + d.ToString() + gamepadTriggers(t))
  141.                                 buttonsAlwaysDown = true
  142.                                 if (debugCheck)
  143.                                     SendDebugMessage("Always Down " + gamepadTriggers(t), 3)
  144.                                 end if
  145.                             end if
  146.                         end if
  147.                     next
  148.                 end if
  149.                
  150.             end if
  151.         next
  152.     End function
  153.    
  154.    
  155.     Private Function GetReverseMouseButton(ByRef buttonSet as boolean)
  156.         'Check Always Down Mouse Button for "Unpressed" state
  157.         if ((buttonsAlwaysDown) and (buttonsAlwaysDownList isNot nothing))
  158.             for each buttonAlwaysDown as string in buttonsAlwaysDownList
  159.                 if (buttonAlwaysDown.EndsWith("MOUSEBUTTON"))
  160.                     if ((vaProxy.Utility.ParseTokens("{" + buttonAlwaysDown + "}")) = "0")
  161.                         buttonSet = true
  162.                         buttonDown = buttonAlwaysDown 'changed from buttonCheck Sept2021
  163.                         VA.SetBoolean("~avcs_ptt_reverse", true)
  164.                         if (debugCheck)
  165.                             SendDebugMessage("(DST)- REVERSE MOUSE BUTTON (" + buttonDown + ") SET", 2)
  166.                         end if
  167.                     end if
  168.                 end if
  169.             next
  170.         end if
  171.     End Function
  172.    
  173.    
  174.     Private Function GetMouseButton(ByRef buttonSet as boolean)
  175.         'Mouse Button Current States
  176.         if ((vaProxy.Utility.ParseTokens("{STATE_ANYMOUSEDOWN}")) <> "0")
  177.             for m as integer = 0 to 4
  178.                 if (buttonSet = false)
  179.                     if ((vaProxy.Utility.ParseTokens("{"+ mouseButtons(m) +"}")) <> "0")
  180.                         buttonCheck = mouseButtons(m)
  181.                         if ((buttonsAlwaysDown) and (buttonsAlwaysDownList isNot nothing))
  182.                             if (not(buttonsAlwaysDownList.Contains(buttonCheck)))
  183.                                 buttonSet = true
  184.                                 buttonDown = buttonCheck
  185.                                 if (debugCheck)
  186.                                     SendDebugMessage("(DST)- MOUSE BUTTON (" + mouseButtons(m) + ") SET", 2)
  187.                                 end if
  188.                             else
  189.                                 if (debugCheck)
  190.                                     SendDebugMessage("MOUSE BUTTON (" + mouseButtons(m) + ") DISREGARED - DISCOVERED ON LIST", 4)
  191.                                 end if
  192.                             end if
  193.                         else
  194.                             buttonSet = true
  195.                             buttonDown = buttonCheck
  196.                             if (debugCheck)
  197.                                 SendDebugMessage("MOUSE BUTTON (" + mouseButtons(m) + ") SET", 2)
  198.                             end if
  199.                         end if
  200.                     end if
  201.                 end if
  202.             next
  203.         end if
  204.     End Function
  205.    
  206.    
  207.     Private Function GetReverseKeyboardKey(ByRef buttonSet as boolean)
  208.         'Check Always Down Keyboard Key for "Unpressed" state
  209.         if ((buttonsAlwaysDown) and (buttonsAlwaysDownList isNot nothing))
  210.             for each buttonAlwaysDown as string in buttonsAlwaysDownList
  211.                 if (buttonSet = false)
  212.                     if (buttonAlwaysDown.StartsWith("STATE_KEYSTATE"))
  213.                         if ((vaProxy.Utility.ParseTokens("{" + buttonAlwaysDown + "}")) <> "1")
  214.                             buttonSet = true
  215.                             buttonDown = buttonAlwaysDown
  216.                             VA.SetBoolean("~avcs_ptt_reverse", true)
  217.                             if (debugCheck)
  218.                                 SendDebugMessage("(DST)- REVERSE KEYBOARD KEY (" + buttonAlwaysDown + ") SET", 2)
  219.                             end if
  220.                         end if
  221.                     end if
  222.                 end if
  223.             next
  224.         end if
  225.     End Function
  226.    
  227.    
  228.     Private Function GetKeyboardKey(ByRef buttonSet as boolean)
  229.         'Keyboard Keys Current State Loop
  230.         if ((vaProxy.Utility.ParseTokens("{STATE_ANYKEYDOWN}")) <> "0")
  231.             for k as integer = 1 to 254
  232.                 if (buttonSet = false)
  233.                     if ((vaProxy.Utility.ParseTokens("{STATE_KEYSTATE:" + k.ToString() + "}")) = "1")
  234.                         buttonCheck = "STATE_KEYSTATE:" + k.ToString()
  235.                         if ((buttonsAlwaysDown) and (buttonsAlwaysDownList isNot nothing))
  236.                             if (not(buttonsAlwaysDownList.Contains(buttonCheck)))
  237.                                 buttonSet = true
  238.                                 buttonDown = buttonCheck
  239.                                 if (debugCheck)
  240.                                     SendDebugMessage("(DST)- KEYBOARD KEY (virtual-key code " + k.ToString() + ") SET", 2)
  241.                                 end if
  242.                             else
  243.                                 if (debugCheck)
  244.                                     SendDebugMessage("KEYBOARD KEY (virtual-key code " + k.ToString() + ") DISREGARED - DISCOVERED ON LIST", 4)
  245.                                 end if
  246.                             end if
  247.                         else
  248.                             buttonSet = true
  249.                             buttonDown = buttonCheck
  250.                             if (debugCheck)
  251.                                 SendDebugMessage("KEYBOARD KEY (virtual-key code " + k.ToString() + ") SET", 2)
  252.                             end if
  253.                         end if
  254.                     end if
  255.                 end if
  256.             next
  257.         end if
  258.     End Function
  259.    
  260.    
  261.     'Check Always Down Style Joystick Buttons for "Unpressed" state
  262.     Private Function GetReverseJoystickButton(ByRef buttonSet as boolean)
  263.         for d as integer = 1 to 4
  264.             if ((vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "ENABLED}")) = "1")
  265.                 if ((buttonsAlwaysDown) and (buttonsAlwaysDownList isNot nothing))
  266.                     for each buttonAlwaysDown as string in buttonsAlwaysDownList
  267.                         if (buttonSet = false)
  268.                             if (buttonAlwaysDown.StartsWith("STATE_JOYSTICK" + d.ToString()))
  269.                                 if ((vaProxy.Utility.ParseTokens("{" + buttonAlwaysDown + "}")) = "0")
  270.                                     buttonSet = true
  271.                                     buttonDown = buttonAlwaysDown 'changed from buttonCheck Sept2021
  272.                                     VA.SetBoolean("~avcs_ptt_reverse", true)
  273.                                     if (debugCheck)
  274.                                         SendDebugMessage("(DST)- REVERSE JOYSTICK " + d.ToString() + " BUTTON (" + buttonAlwaysDown + ") HAS BEEN SET", 2)
  275.                                     end if
  276.                                 end if
  277.                             end if
  278.                         end if
  279.                     next
  280.                 end if
  281.             end if
  282.         next
  283.     End Function
  284.    
  285.    
  286.     'Standard Button Current "Pressed" state
  287.     Private Function GetJoystickButton(ByRef buttonSet as boolean)
  288.         for d as integer = 1 to 4
  289.             if ((vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "ENABLED}")) = "1")
  290.                 if ((vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "ANYBUTTON}")) = "1")
  291.                     for i as integer = 1 to 128
  292.                         if (buttonSet = false)
  293.                             if ((vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "BUTTON:" + i.ToString() + "}")) = "1")
  294.                                 buttonCheck = "STATE_JOYSTICK" + d.ToString() + "BUTTON:" + i.ToString()
  295.                                 if ((buttonsAlwaysDown) and (buttonsAlwaysDownList isNot nothing))
  296.                                     if (not(buttonsAlwaysDownList.Contains(buttonCheck)))
  297.                                         buttonSet = true
  298.                                         buttonDown = buttonCheck
  299.                                         if (debugCheck)
  300.                                             SendDebugMessage("(DST)- JOYSTICK " + d.ToString() + " BUTTON " + i.ToString() + " SET", 2)
  301.                                         end if
  302.                                     else
  303.                                         if (debugCheck)
  304.                                             SendDebugMessage("JOYSTICK " + d.ToString() + " BUTTON " + i.ToString() + " DISREGARED - DISCOVERED ON LIST", 4)
  305.                                         end if
  306.                                     end if
  307.                                 else
  308.                                     buttonSet = true
  309.                                     buttonDown = buttonCheck
  310.                                     if (debugCheck)
  311.                                         SendDebugMessage("JOYSTICK " + d.ToString() + " BUTTON " + i.ToString() + " SET", 2)
  312.                                     end if
  313.                                 end if
  314.                             end if
  315.                         end if
  316.                     next
  317.                 end if
  318.             end if
  319.         next
  320.     End Function
  321.    
  322.     'Check Always Down POV for "Unpressed" state
  323.     Private Function GetReverseJoystickPOV(ByRef buttonSet as boolean)
  324.         for d as integer = 1 to 4
  325.             if ((vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "POVENABLED}")) = "1")
  326.                 for i as integer = 1 to 4
  327.                     checkPOV = "STATE_JOYSTICK" + d.ToString() + "POV" + i.toString()
  328.                     if ((buttonsAlwaysDown) and (buttonsAlwaysDownList isNot nothing))
  329.                         if (buttonsAlwaysDownList.Contains(checkPOV))
  330.                             for each buttonAlwaysDown as string in buttonsAlwaysDownList
  331.                                 if (buttonSet = false) and (buttonAlwaysDown.StartsWith(checkPOV))
  332.                                     if ((vaProxy.Utility.ParseTokens("{" + checkPOV + "}")) = "CENTER")
  333.                                         buttonSet = true
  334.                                         buttonDown = buttonAlwaysDown
  335.                                         VA.SetBoolean("~avcs_ptt_reverse", true)
  336.                                         if (debugCheck)
  337.                                             SendDebugMessage("(DST)- REVERSE JOYSTICK " + d.ToString() + " POV (" + buttonAlwaysDown + ") HAS BEEN SET", 2)
  338.                                         end if
  339.                                     end if
  340.                                 end if
  341.                             next
  342.                         end if
  343.                     end if
  344.                 next
  345.             end if
  346.         next
  347.     End Function
  348.    
  349.     'Check Joystick POV for "Pressed" state
  350.     Private Function GetJoystickPOV(ByRef buttonSet as boolean)
  351.         for d as integer = 1 to 4
  352.             if ((vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "POVENABLED}")) = "1")
  353.                 for i as integer = 1 to 4
  354.                     if (buttonSet = false)
  355.                         if ((vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "POV" + i.toString() + "TYPE}")) = "4")
  356.                             checkPOV = vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "POV" + i.toString() + "}")
  357.                             if (checkPOV <> "CENTER")
  358.                                 buttonCheck = "STATE_JOYSTICK" + d.ToString() + "POV" + i.toString() + ":" + checkPOV
  359.                                 if ((buttonsAlwaysDown) and (buttonsAlwaysDownList isNot nothing))
  360.                                     if (not(buttonsAlwaysDownList.Contains(buttonCheck)))
  361.                                         buttonSet = true
  362.                                         buttonDown = buttonCheck
  363.                                         if (debugCheck)
  364.                                             SendDebugMessage("JOYSTICK " + d.ToString() + "POV" + i.ToString() + ":" + checkPOV + " SET", 2)
  365.                                         end if
  366.                                     else
  367.                                         if (debugCheck)
  368.                                             SendDebugMessage("JOYSTICK " + d.ToString() + "POV" + i.ToString() + ":" + checkPOV + " DISREGARED - DISCOVERED ON LIST", 4)
  369.                                         end if
  370.                                     end if
  371.                                 else
  372.                                     buttonSet = true
  373.                                     buttonDown = buttonCheck
  374.                                     if (debugCheck)
  375.                                         SendDebugMessage("JOYSTICK " + d.ToString() + "POV" + i.ToString() + ":" + checkPOV + " SET", 2)
  376.                                     end if
  377.                                 end if
  378.                             end if
  379.                         end if
  380.                     end if
  381.                 next
  382.             end if
  383.         next
  384.     End Function
  385.    
  386.     '---------------------------------------------------------------------------
  387.     '---------------------------------------------------------------------------
  388.    
  389.     'Check Always Down Triggers for "Unpressed" state
  390.     Private Function GetReverseJoystickTrigger(ByRef buttonSet as boolean)
  391.         for d as integer = 1 to 4
  392.             if (((vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "ENABLED}")) = "1") and ((vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "ISGAMEPAD}")) = "1"))
  393.                 if ((buttonsAlwaysDown) and (buttonsAlwaysDownList isNot nothing))
  394.                     for each buttonAlwaysDown as string in buttonsAlwaysDownList
  395.                         if (buttonSet = false)
  396.                             if (buttonAlwaysDown.EndsWith("TRIGGER"))
  397.                                 if (IsNumeric(vaProxy.Utility.ParseTokens("{" + buttonAlwaysDown + "}")))
  398.                                     if ((Convert.ToInt32(vaProxy.Utility.ParseTokens("{" + buttonAlwaysDown + "}"))) < 20)
  399.                                         buttonSet = true
  400.                                         buttonDown = buttonCheck
  401.                                         VA.SetBoolean("~avcs_ptt_reverse", true)
  402.                                         if (debugCheck)
  403.                                             SendDebugMessage("(DST)- REVERSE JOYSTICK GAMEPAD " + d.ToString() + " TRIGGER (" + buttonAlwaysDown + ") HAS BEEN SET", 2)
  404.                                         end if
  405.                                     end if
  406.                                 end if
  407.                             end if
  408.                         end if
  409.                     next
  410.                 end if
  411.             end if
  412.         next
  413.     End Function
  414.    
  415.     'Check Triggers for "Pressed" state
  416.     Private Function GetJoystickTrigger(ByRef buttonSet as boolean)
  417.         for d as integer = 1 to 4
  418.             if (((vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "ENABLED}")) = "1") and ((vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + "ISGAMEPAD}")) = "1"))
  419.                 'Gamepad Triggers Current State (with 20 of 255 as 'deadzone')
  420.                 for t as integer = 0 to 1
  421.                     if (buttonSet = false)
  422.                         if (IsNumeric(vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + gamepadTriggers(t) + "}")))
  423.                             if ((Convert.ToInt32(vaProxy.Utility.ParseTokens("{STATE_JOYSTICK" + d.ToString() + gamepadTriggers(t) + "}"))) > 20)
  424.                                 buttonCheck = "STATE_JOYSTICK" + d.ToString() + gamepadTriggers(t)
  425.                                 if ((buttonsAlwaysDown) and (buttonsAlwaysDownList isNot nothing))
  426.                                     if (not(buttonsAlwaysDownList.Contains(buttonCheck)))
  427.                                         buttonSet = true
  428.                                         buttonDown = buttonCheck
  429.                                     else
  430.                                         if (debugCheck)
  431.                                             SendDebugMessage("JOYSTICK GAMEPAD " + d.ToString() + gamepadTriggers(t) + " DISREGARED - DISCOVERED ON LIST", 4)
  432.                                         end if
  433.                                     end if
  434.                                 else
  435.                                     buttonSet = true
  436.                                     buttonDown = buttonCheck
  437.                                     if (debugCheck)
  438.                                         SendDebugMessage("JOYSTICK GAMEPAD " + d.ToString() + gamepadTriggers(t) + " SET", 2)
  439.                                     end if
  440.                                 end if
  441.                             end if
  442.                         end if
  443.                     end if
  444.                 next
  445.             end if
  446.         next
  447.     End Function
  448.    
  449.    
  450.    
  451.     Public Sub Main()
  452.        
  453.         if (VA.GetBoolean("AVCS_Debug_ON") IsNot nothing)
  454.             debugCheck = VA.GetBoolean("AVCS_Debug_ON")
  455.         end if
  456.        
  457.         if ((VA.GetText("AVCS_ACTIVE_PROFILE")) isNot nothing)
  458.             activeProfile = VA.GetText("AVCS_ACTIVE_PROFILE")
  459.         end if
  460.        
  461.         if (debugCheck)
  462.             VA.ClearLog()
  463.             SendDebugMessage("inline begin....", 3)
  464.         end if
  465.        
  466.        
  467.         'Get Button/Key Baseline States
  468.         BuildPTTkeysList()
  469.         BuildAlwaysDownList()
  470.         VA.SetBoolean("~avcs_getting_input", true)
  471.        
  472.         if (debugCheck)
  473.             SendDebugMessage("Always Down Array Complete", 3)
  474.         end if
  475.        
  476.         'Begin a pause loop to wait for timeout or user input (key/button press or voice 'cancel' phrase)
  477.         while (not(userReady))
  478.             Thread.CurrentThread.Sleep(1000)
  479.             counter += 1
  480.            
  481.             'Check for Timeout or TTS User Prompt Instructions complete
  482.             if ((VA.GetBoolean("~avcs_user_ready")) isNot nothing)
  483.                 userReady = VA.GetBoolean("~avcs_user_ready")
  484.             end if
  485.             if ((counter >= 15) or (userReady))
  486.                 if (userReady)
  487.                     VA.WriteToLog("== PLEASE PRESS ANY KEY OR BUTTON NOW ==","green")
  488.                 else
  489.                     VA.WriteToLog("cancelled - command timed out... TTS or primary function error","red")
  490.                     if (debugCheck)
  491.                         SendDebugMessage("AVCS PTT SET cancelled - command timed out", 3)
  492.                     end if
  493.                     VA.SetBoolean("~avcs_getting_input", false)
  494.                     Exit sub
  495.                 end if
  496.             end if
  497.         end while
  498.        
  499.        
  500.         'Reset counter for Keypress/Button monitor
  501.         counter = 0
  502.         userReady = false
  503.         VA.SetBoolean("~avcs_user_ready", false)
  504.        
  505.        
  506.         'Begin a pause loop to wait for Joystick/Gamepad Input or spoken 'cancel/done' speech
  507.         while (not(userReady))
  508.             Thread.CurrentThread.Sleep(75)
  509.             counter += 1
  510.            
  511.             if (buttonSet = false)
  512.                 GetReverseMouseButton(buttonSet)
  513.                 GetMouseButton(buttonSet)
  514.                 GetReverseKeyboardKey(buttonSet)
  515.                 GetKeyboardKey(buttonSet)
  516.                 GetReverseJoystickButton(buttonSet)
  517.                 GetJoystickButton(buttonSet)
  518.                 GetReverseJoystickPOV(buttonSet)
  519.                 GetJoystickPOV(buttonSet)
  520.                 GetReverseJoystickTrigger(buttonSet)
  521.                 GetJoystickTrigger(buttonSet)
  522.             end if
  523.            
  524.             'Check for Input, Timeout or TTS User Prompt Instructions complete
  525.             if ((VA.GetBoolean("~avcs_user_ready")) isNot nothing)
  526.                 userReady = VA.GetBoolean("~avcs_user_ready")
  527.             end if
  528.             if ((counter >= 200) or ((buttonSet) and (buttonDown <> "")) or (userReady))
  529.                 if ((buttonSet) and (buttonDown <> ""))
  530.                     if (buttonsAlreadySetList isNot nothing)
  531.                         if (buttonsAlreadySetList.Contains(buttonDown))
  532.                             VA.SetBoolean("~avcs_getting_input", false)
  533.                             VA.SetText("~avcs_button_choice", "alreadyset")
  534.                             if (debugCheck)
  535.                                 SendDebugMessage("ERROR - Existing PTT button has already been set to " + buttonDown, 4)
  536.                             end if
  537.                             Exit While
  538.                         end if
  539.                     end if
  540.                     VA.SetBoolean("~avcs_getting_input", false)
  541.                     VA.SetText("~avcs_button_choice", buttonDown)
  542.                     if (debugCheck)
  543.                         SendDebugMessage("PTT button has been set " + buttonDown, 2)
  544.                     end if
  545.                     Exit While
  546.                 elseif (userReady)
  547.                     VA.SetBoolean("~avcs_getting_input", false)
  548.                     VA.WriteToLog("command cancelled - user input not detected","red")
  549.                     if (debugCheck)
  550.                         SendDebugMessage("AVCS PTT SET user input not detected", 4)
  551.                     end if
  552.                     Exit While
  553.                 elseif (counter >= 200)
  554.                     VA.SetBoolean("~avcs_getting_input", false)
  555.                     VA.WriteToLog("command timed out... user input not detected","red")
  556.                     if (debugCheck)
  557.                         SendDebugMessage("AVCS PTT SET command timed out", 4)
  558.                     end if
  559.                     Exit While
  560.                 end if
  561.             end if
  562.         end while
  563.        
  564.         if ((buttonSet) and (buttonDown <> ""))
  565.             if (buttonDown.StartsWith("STATE_KEYSTATE:"))
  566.                 keyCode = buttonDown.Split(":")
  567.                 if (IsNumeric(keyCode(1)))
  568.                     try
  569.                         keyString = kc.ConvertToString(Convert.ToInt32(keyCode(1)))
  570.                         keyString = keyString.Replace("Oem","")
  571.                         VA.WriteToLog("PTT Button Set to " + buttonDown + " == " + keyString, "green")
  572.                     catch
  573.                         VA.WriteToLog("PTT Button Set to " + buttonDown, "green")
  574.                     end try
  575.                 end if
  576.             else
  577.                 VA.WriteToLog("PTT Button Set to " + buttonDown, "green")
  578.             end if
  579.         end if
  580.        
  581.     End Sub
  582.  
  583. End Class
Add Comment
Please, Sign In to add comment