Author Topic: Can't get keystate check to work with two key indicators  (Read 5169 times)

mikelimtw

  • Jr. Member
  • **
  • Posts: 51
Can't get keystate check to work with two key indicators
« on: January 08, 2017, 07:04:20 PM »
I am trying to use the keystate token to check for two key indictors: LALT + ENTER, but it doesn't seem to be working. I have the command as {STATE_KEYSTATE:[LALT][ENTER]}. What am I doing wrong?

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2826
Re: Can't get keystate check to work with two key indicators
« Reply #1 on: January 08, 2017, 07:14:59 PM »
You'll want to drop the square brackets as well as check each key, one at a time (the token only gives the state for one key):

Begin Text Compare : [{STATE_KEYSTATE:ENTER}] Equals '1'
    Begin Text Compare : [{STATE_KEYSTATE:LALT}] Equals '1'
        Write '[Orange] Yes' to log
    End Condition
Else
    Write '[Orange] No' to log
End Condition


mikelimtw

  • Jr. Member
  • **
  • Posts: 51
Re: Can't get keystate check to work with two key indicators
« Reply #2 on: January 08, 2017, 07:46:31 PM »
That's what it was... keystate can only check one key at a time. If that is the case, I can do following correct? (it's a lot cleaner)

Begin Text Compare : [{EXP:{STATE_KEYSTATE:LALT} And {STATE_KEYSTATE:ENTER}}] Equals '1'

I am curious why you chose to use nested IF-THEN compare as opposed to evaluating it using the EXP token? Is it because the EXP is a beta function and might change in the future?

EDIT: Nevermind, I just realized why that doesn't work. You can't make the EXP token check both keypresses at the same time as keystate can only hold one keypress at a time.
« Last Edit: January 08, 2017, 08:04:36 PM by mikelimtw »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
Re: Can't get keystate check to work with two key indicators
« Reply #3 on: January 08, 2017, 08:40:18 PM »
You can't make the EXP token check both keypresses at the same time as keystate can only hold one keypress at a time.
You can:
Code: [Select]
Begin Text Compare : [{EXP:{STATE_KEYSTATE:LALT} = 1 And {STATE_KEYSTATE:ENTER} = 1}] Equals '1'Will return "1" only when both statements are true.

However, for your purposes there is a slightly simpler method:
Code: [Select]
Begin Text Compare : [{EXP:{STATE_KEYSTATE:LALT} + {STATE_KEYSTATE:ENTER}}] Equals '2'

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2826
Re: Can't get keystate check to work with two key indicators
« Reply #4 on: January 08, 2017, 09:04:51 PM »
Quote
I am curious why you chose to use nested IF-THEN compare as opposed to evaluating it using the EXP token? Is it because the EXP is a beta function and might change in the future?

I thought about EXP up front, but most normal VA users would even be put off their feed just by if-then statements. 

Also, (since I have no idea about your technical skill, you'll have to forgive me) if someone wasn't clear on using {STATE_KEYSTATE:[LALT][ENTER]}, this:
Code: [Select]
Begin Text Compare : [{EXP:{STATE_KEYSTATE:LALT} = 1 And {STATE_KEYSTATE:ENTER} = 1}] Equals '1' would probably make more questions than provide a solution ;)

I might want to remove the, 'beta' disclaimer from EXP... it's been like that for years :)

mikelimtw

  • Jr. Member
  • **
  • Posts: 51
Re: Can't get keystate check to work with two key indicators
« Reply #5 on: January 08, 2017, 09:35:13 PM »
You can't make the EXP token check both keypresses at the same time as keystate can only hold one keypress at a time.
You can:
Code: [Select]
Begin Text Compare : [{EXP:{STATE_KEYSTATE:LALT} = 1 And {STATE_KEYSTATE:ENTER} = 1}] Equals '1'Will return "1" only when both statements are true.

However, for your purposes there is a slightly simpler method:
Code: [Select]
Begin Text Compare : [{EXP:{STATE_KEYSTATE:LALT} + {STATE_KEYSTATE:ENTER}}] Equals '2'

Does my version up top work? Do we have to test explicitly within the EXP that each keypress = 1 or can it be implied?

mikelimtw

  • Jr. Member
  • **
  • Posts: 51
Re: Can't get keystate check to work with two key indicators
« Reply #6 on: January 08, 2017, 09:38:45 PM »
Quote
I am curious why you chose to use nested IF-THEN compare as opposed to evaluating it using the EXP token? Is it because the EXP is a beta function and might change in the future?

I thought about EXP up front, but most normal VA users would even be put off their feed just by if-then statements.

Also, (since I have no idea about your technical skill, you'll have to forgive me) if someone wasn't clear on using {STATE_KEYSTATE:[LALT][ENTER]}, this:
Code: [Select]
Begin Text Compare : [{EXP:{STATE_KEYSTATE:LALT} = 1 And {STATE_KEYSTATE:ENTER} = 1}] Equals '1' would probably make more questions than provide a solution ;)

I might want to remove the, 'beta' disclaimer from EXP... it's been like that for years :)

Actually, your code is quite clear and it filled in the missing blanks for me on how to use this token. I misread the information on keystate in the help file. It probably could have been worded a bit differently to make the information more clear. I do have programming experience so feel free to use more complex constructs; it won't phase me. Thanks to you both for your patience and help!
« Last Edit: January 08, 2017, 09:43:03 PM by mikelimtw »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
Re: Can't get keystate check to work with two key indicators
« Reply #7 on: January 09, 2017, 11:15:35 AM »
Do we have to test explicitly within the EXP that each keypress = 1 or can it be implied?
You'll have to test each explicitly. "1" and "0" are always treated as integers.
"{EXP:}" does support implied testing of booleans, but it looks for "true" or "false".

As tokens always convert the input sting, the datatype that produces "true" or "false" doesn't matter:
Code: [Select]
Set Boolean [true] to True
Set Text [true] to 'true'
Write '[Purple] {EXP:{BOOL:true} And {TXT:true}}' to log
Will return "1".