Jump to content
Sign in to follow this  
Xiengsaephan

Sending Command According to ComboBox

Recommended Posts

Xiengsaephan

Hi, I have a script that presses the keys A, then S, then D, then F.

I want to then send a SPACE after one of those letters depending on which item on my combobox is selected. here is how my code looks like

Func Example()
Local $idComboBox = GUICtrlCreateCombo("After A", 20, 20, 150, 20)

   GUICtrlSetData($idComboBox, "After S|After D|After F", "After A")
    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)


ControlSend("NotePad","","","A") 
Sleep (150)
ControlSend("NotePad","","","S")
Sleep (150)
ControlSend("NotePad","","","D") 
Sleep (150)
ControlSend("NotePad","","","F") 
Sleep (150)

I tried to a line like this after each of the other command but it didnt work. 

If $idComboBox = "After A" Then ControlSend("NotePad","","","{SPACE}")
 
  If $idComboBox = "After S" Then ControlSend("NotePad","","","{SPACE}")
  
   If $idComboBox = "After D" Then ControlSend("NotePad","","","{SPACE}")
   
    If $idComboBox = "After F" Then ControlSend("NotePad","","","{SPACE}")

What would be the best way?

Share this post


Link to post
Share on other sites
quickbeam

You are indenting the if-then statements as if they are nested.  Is that true?  As written, I don't see a problem but if those statements are nested, your "After S" test would never be reached because it would first fail the "After A" test.

Hmm, I think what you're saying is that the 4 lines in the second part are actually intermixed in the code above.

In that case, maybe you need to add short delays so the OS has time to pick up the key presses (a space is like any other key, and there's debounce going on to eliminate double-reads and such, so a timeout is needed before the next key comes along).

Edited by quickbeam
  • Like 1

Share this post


Link to post
Share on other sites
Xiengsaephan
7 hours ago, quickbeam said:

You are indenting the if-then statements as if they are nested.  Is that true?  As written, I don't see a problem but if those statements are nested, your "After S" test would never be reached because it would first fail the "After A" test.

Hmm, I think what you're saying is that the 4 lines in the second part are actually intermixed in the code above.

In that case, maybe you need to add short delays so the OS has time to pick up the key presses (a space is like any other key, and there's debounce going on to eliminate double-reads and such, so a timeout is needed before the next key comes along).

You're correct, the 4 lines were intermixed with the other code. I added another short delay and it works now, thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.