Author Topic: Checking pressing  (Read 25153 times)

0 Members and 1 Guest are viewing this topic.

NooBAsTiK

  • Jr. Member
  • **
  • Posts: 33
  • Karma: 0
    • View Profile
    • SquaD Skulls
Checking pressing
« on: January 25, 2015, 09:45:45 AM »
Hey there! By not saying use English translator. I dig the program for 2 days. How to do a background check on pressing if the button has been pressed then leave me a message that it is already pressed, but if not then press it. This is for the game. :bonk

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Checking pressing
« Reply #1 on: January 25, 2015, 10:45:07 AM »
Hi NooBAsTiK.

I think you probably want to use the "hook" plugin.
http://voxcommando.com/mediawiki/index.php?title=Plugin_Hook

This plugin can generate an event when you press or release a button.

I don't think there is any way to know if a button is already pressed or not, but you can use a variable to keep track of key press and and key release events.

You must enable the hook plugin, and tell it which keys to monitor.  (See the attached image.)

For example, when you press the left-Ctrl key on your keyboard, hook will generate this event:
Code: [Select]
<event>Hook.LControlKey</event>and when you release the key this event will be generated:
Code: [Select]
<event>Hook.LControlKey.Up</event>
You could use these events to monitor the current state of the Ctrl key.

NooBAsTiK

  • Jr. Member
  • **
  • Posts: 33
  • Karma: 0
    • View Profile
    • SquaD Skulls
Re: Checking pressing
« Reply #2 on: January 25, 2015, 10:55:50 AM »
Thank you very much, I think this is what you need. Try to understand.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Checking pressing
« Reply #3 on: January 25, 2015, 12:48:24 PM »
In the future, please feel free to post to the forum in Russian.

NooBAsTiK

  • Jr. Member
  • **
  • Posts: 33
  • Karma: 0
    • View Profile
    • SquaD Skulls
Re: Checking pressing
« Reply #4 on: January 25, 2015, 02:28:57 PM »
OK. Пытаюсь сделать запись видео по комаде голосом. Активация записи и дективация производиться кнопками LCTRL+R. Включил плагин добавил сочетание клавиш.
Создал событие в команде. Сделал логическую цепочку в комананде: "если запись не включена lctrl+r, если включена сообщение "запись уже идет". Что я делаю не так?

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Checking pressing
« Reply #5 on: January 25, 2015, 03:56:45 PM »
I think it would help us if we knew what you are trying to do.  It would also help if we knew why you were trying to do this.  Maybe you can explain what you are trying to accomplish in the game.

One thing that is important to know is that the "DxInput.KeyCombo" action will press the keys and then release them after a very short delay.  If you need to keep the keys down for a very long time then you should use the action: "DxInput.KeyDown" which will press the keys and leave them pressed down.  Later you must use "DxInput.KeyUp" to release the keys!

If you use the action "DxInput.KeyDown" to press a key that has already been pressed down, nothing will happen, so I don't think you need to check if the key is already pressed down.

Finally, if you want to show us a command that you need help with, it is better to copy the command and then paste it into a code box like this, instead of uploading a jpg image:
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.3.6-->
<command id="589" name="show help" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Help.ShowAll</cmdType>
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>show help</phrase>
</command>
« Last Edit: January 25, 2015, 04:05:18 PM by jitterjames »

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Checking pressing
« Reply #6 on: January 25, 2015, 04:03:46 PM »
This is how you can share commands or command groups:

http://www.screencast.com/t/0SOZw4TEvq9

Это, как вы можете легко поделиться команды или группы команд
« Last Edit: March 14, 2015, 10:09:15 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Checking pressing
« Reply #7 on: January 25, 2015, 06:03:58 PM »
Based on jitterjames's advice in the post above, you may not need to use the "Hook" plugin. It depends on your final objective.

Here is an example of using "DxInput.KeyDown" and "DxInput.KeyUp" that uses logic and a variable to track the state of the button. I hope it helps.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.3.6-->
<commandGroup open="True" name="Example of DXInput Key down/Key up" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="296" name="turn Flight assist off" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="Results.SetVar --&gt; create a variable called &quot;ctrl-r&quot; and set it to True.">
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)==(B)</ifType>
      <ifParams>{var.ctrl-r}&amp;&amp;True</ifParams>
      <then>
        <action>
          <cmdType>OSD.ShowText</cmdType>
          <params>
            <param>Flight assist is already off.</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>DxInput.KeyDown</cmdType>
          <params>
            <param>LeftControl</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>DxInput.KeyDown</cmdType>
          <params>
            <param>R</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>Results.SetVar</cmdType>
          <params>
            <param>ctrl-r</param>
            <param>True</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>OSD.ShowText</cmdType>
          <params>
            <param>OK. Turning off flight assist.</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </else>
    </if>
    <phrase>turn Flight assist off</phrase>
  </command>
  <command id="298" name="Turn on flight assist" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>DxInput.KeyUp</cmdType>
      <params>
        <param>LeftControl</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>DxInput.KeyUp</cmdType>
      <params>
        <param>R</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.SetVar</cmdType>
      <params>
        <param>ctrl-r</param>
        <param>False</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>Turning flight assist back on.</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Turn on flight assist</phrase>
  </command>
</commandGroup>
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

NooBAsTiK

  • Jr. Member
  • **
  • Posts: 33
  • Karma: 0
    • View Profile
    • SquaD Skulls
Re: Checking pressing
« Reply #8 on: January 26, 2015, 04:44:14 AM »
Спасибо! Попробую когда вернусь домой.
« Last Edit: January 26, 2015, 06:33:04 AM by NooBAsTiK »

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Checking pressing
« Reply #9 on: January 26, 2015, 11:24:03 AM »
В предыдущем примере предполагается, что вы хотите проверить, есть ли кнопки по-прежнему нажата или нет. Мы были не уверены, если это то, что вы пытаетесь отслеживать. Если вы просто хотите, чтобы отслеживать, была ли кнопка была нажата один раз быстро, что немного отличается. Вы можете использовать "Hook" плагин с переменными в этой второй ситуации.

В следующем примере мы отслеживаем ли "Z" кнопка была нажата один раз быстро. Если нет, то программа будет нажать и отпустить кнопку "Z". Но после того, как кнопка была нажата один раз, то программа никогда не будет снова нажать кнопку, поскольку переменная остается "True". Вы можете изменить условия. Это лишь пример.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.3.6-->
<commandGroup open="True" name="Elite Dangerous test" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="444" name="Switch on (включать)" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)==(B)</ifType>
      <ifParams>{var.toggle-z}&amp;&amp;True</ifParams>
      <then>
        <action>
          <cmdType>OSD.ShowText</cmdType>
          <params>
            <param>Я не буду ничего делать. Это было сделано раньше.</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>VC.TriggerEvent</cmdType>
          <params>
            <param>Hook.Z</param>
          </params>
          <cmdRepeat>0</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>OSD.ShowText</cmdType>
          <params>
            <param>включать</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>DxInput.KeyPress</cmdType>
          <params>
            <param>z</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </else>
    </if>
    <phrase>Switch on, включать</phrase>
  </command>
  <command id="446" name="Set the variable (установить переменную)" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)==(B)</ifType>
      <ifParams>{var.toggle-z}&amp;&amp;False</ifParams>
      <then>
        <action>
          <cmdType>Results.SetVar</cmdType>
          <params>
            <param>toggle-z</param>
            <param>True</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>Results.SetVar</cmdType>
          <params>
            <param>toggle-z</param>
            <param>False</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </else>
    </if>
    <event>VC.Loaded</event>
    <event>Hook.Z</event>
  </command>
</commandGroup>

The example in the previous post assumes that you want to check if a key combination is still pressed down or not. We were not sure if this is what you are actually trying to monitor. If you just want to keep track of whether the key has been pressed once, quickly, that is a little different. You can use the "Hook" plugin with variables in this second situation.

In the following example, we keep track of whether the "Z" key was pressed once quickly. If not, the program will press and release the "Z" key. But after it has been pressed once, the program will never again press the button, because the variable remains "true". You can change these conditions to be more sophisticated. This is just an example.
« Last Edit: January 26, 2015, 11:28:54 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

NooBAsTiK

  • Jr. Member
  • **
  • Posts: 33
  • Karma: 0
    • View Profile
    • SquaD Skulls
Re: Checking pressing
« Reply #10 on: January 26, 2015, 02:40:49 PM »
Очень хороший пример, я пока не совсем понимаю как работают переменные типа {var.togglez}, их много и описание на английском  ;)

A very good example, I do not quite understand how the variables of type {var.togglez}, a lot of them and a description in English;)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Checking pressing
« Reply #11 on: January 26, 2015, 02:48:07 PM »
Maybe this simple example will make it more clear.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.3.6-->
<command id="1164" name="simple variable example." enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>A</param>
      <param>Hello!</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>B</param>
      <param>Goodbye :'(</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{Var.A}{CR}{Var.B}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
</command>

Phobophile

  • Jr. Member
  • **
  • Posts: 36
  • Karma: 7
    • View Profile
    • Facebook
Re: Checking pressing
« Reply #12 on: January 27, 2015, 09:04:19 AM »
Очень хороший пример, я пока не совсем понимаю как работают переменные типа {var.togglez}, их много и описание на английском  ;)
На самом деле, переменных нужно не много, а всего одна в твоём случае, та, которая определяет была ли включена запись (например, isrecording со значениями 0 и 1)
Присвоить значение переменной можно с помощью команды Results.SetVar.
Считать значение можно так - {var.isrecording}.
То есть, в случае команды "Включить запись" - проверяешь, что isrecording==0, посылаешь комбинацию клавиш ctrl+L, присваиваешь isrecording=1. В противном случае - говоришь "запись уже стартовала".
Ну и аналогично для "выключить запись", только наоборот.
К сожалению, нет под рукой сейчас VoxCommando, чтобы сгенерить примерный скрипт, но если что непонятно, то спрашивай.

NooBAsTiK

  • Jr. Member
  • **
  • Posts: 33
  • Karma: 0
    • View Profile
    • SquaD Skulls
Re: Checking pressing
« Reply #13 on: January 27, 2015, 10:18:16 AM »
Да у меня будет посложнее задача.
Кратно: Я играю в авиасимулятор и часто пользуюсь закрылками которые выпускаются от 0 до 60 градусов. Для себя определил 4 положения:
1. 0 градусов - полет
2. 8-9 градусов - боевое положение (время выпуска от 0 до 8-9 градусов около 3 секунд)
3. 17-18 градусов - взлет, маневрирование (от 8-9 около 5 секунд)
4. 50 градусов - посадка (от 18 около 9 секунд)

И вот тут получается следующий вопрос как выстроить логику:
Например я говорю "закрылки посадка"  надо держать кнопку 3+5+9=17 секунд, потом "закрылки боевое"  держать  кнопку которая убирает закрылки надо 9+5=14 секунд и так далее. Просто больше переменных делать? 

Phobophile

  • Jr. Member
  • **
  • Posts: 36
  • Karma: 7
    • View Profile
    • Facebook
Re: Checking pressing
« Reply #14 on: January 27, 2015, 11:13:53 AM »
Я бы сделал одну переменную, которая в разных режимах равна количеству секунд удержания кнопки выпуска закрылок, то есть 0, 3, 8, 17.
Потом можно сделать маппинг - это файл, содержащий пары ключ-значение, в твоем случае будет: 0-полёт, 3- боевое, 8-взлет, 17 - посадка.
Таким образом, в экшене VoxCommando у тебя будут доступен входной параметр, содержащий время удержания от нуля (скажем, для "закрылки боевое" - 3) и переменная текущего состояния (например, посадка = 17). Сравниваешь два значения и определяешь какую из кнопок держать и сколько секунд.