Jump to content

Send keys at the same time?


Recommended Posts

How can I emulate pressing two keys simultaneously? I am developing a music playing "bot" for LOTRO (see here for more information: http://lotro.glenneroo.org/music.html ). In order to play certain chords, I have to "press" multiple keys at the same time. Is there any way to do this? Setting the send key delay to 0 and using Send("12") does NOT press them at the same time. Any ideas?

Link to comment
Share on other sites

So

Send("{1 DOWN}")
Send("{2 DOWN}")
Send("{2 UP}")
Send("{1 UP}")

They need to be pressed and released at the exact same time. I see what you are doing, but, that pushes 1, then 2, then releases 2, then releases 1. there are still those two times where only 1 key is pressed, and thats what I need to avoid.

Link to comment
Share on other sites

They need to be pressed and released at the exact same time. I see what you are doing, but, that pushes 1, then 2, then releases 2, then releases 1. there are still those two times where only 1 key is pressed, and thats what I need to avoid.

I think you misunderstand what it means on a keyboard for the human hand to press two keys "at the exact same time." AutoIt functions complete in microseconds, and the hand can only get "at the exact same time" to within a few milliseconds, at best. I think Zedna's first answer was the best, though the delay was too long at 3 full seconds. For musical purposes, you are going to want some math in the function to hold down the chord for an amount of time specific to the time/meter/beat of the music. The amount of time between the two "downs" or "up" is in microseconds and irrelevant.

$BeatsPerMin = 100
$NoteLen = 0.25 ; quarter note

$NoteTime = ($BeatsPerMin / 60) * 1000 ; miliseconds per beat
$NoteTime = $NoteTime * $NoteLen

Send("{1 DOWN}")
Send("{2 DOWN}")
Sleep($NoteLen)
Send("{1 UP}")
Send("{2 UP}")

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I think you misunderstand what it means on a keyboard for the human hand to press two keys "at the exact same time." AutoIt functions complete in microseconds, and the hand can only get "at the exact same time" to within a few milliseconds, at best. I think Zedna's first answer was the best, though the delay was too long at 3 full seconds. For musical purposes, you are going to want some math in the function to hold down the chord for an amount of time specific to the time/meter/beat of the music. The amount of time between the two "downs" or "up" is in microseconds and irrelevant.

$BeatsPerMin = 100
$NoteLen = 0.25 ; quarter note

$NoteTime = ($BeatsPerMin / 60) * 1000 ; miliseconds per beat
$NoteTime = $NoteTime * $NoteLen

Send("{1 DOWN}")
Send("{2 DOWN}")
Sleep($NoteLen)
Send("{1 UP}")
Send("{2 UP}")

:)

I realize I was mistaken, I am sorry. However, after testing that method, it still does not work. The program does not receive the keys at "the same time" (in quotes because, as you said, its not at EXACTLY the same time) and thus the notes are not played concurrently. Sometimes I will hear the other note just before the other, and sometimes the note is played CLEARLY after the other. Are there any methods of sending keystrokes concurrently?

Link to comment
Share on other sites

This still 'presses' 1 then 2, then releases one. yes, they are depressed concurrently, but not 'pressed' concurrently. the program still plays note 1, then note 2.

I don't think it is possible to press two buttons at exactly the same time, the microsecond or two between each key being pressed is most likely unavoidable. Even when you try pushing two keys on a keyboard there is probably a slight difference between when the keyboard receives them as being pushed.

Correct me if I'm wrong anybody, I'm just guessing based off what I know about programming...

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

Ya, but for some reason, when I press two keys at the same time with my keyboard, it plays both at the same time. But if I send two keys with a microsecond delay with a Send() command, the program thinks there is a pause between them and plays them seperately. I cannot figure this out. Any ideas?

Link to comment
Share on other sites

  • Moderators

This is the most rediculous request I've ever seen.

AutoIt isn't multi-threading, and even if it were, explain to me how something could be done at the same "exact" time... Never mind you can't... so quit bitching with suggestions (considering all you've done is shot down every attempt made) come up with some ideas of your own, switch languages, or learn how to use /AutoIt3ExecuteLine/Script.

Edit:

I should add:

Everything is registered one thing at a time... speed may make it seem like it was done simultaneously, but logic tells us something different.

Having said that, you may want to look at your send key delays.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

This is the most rediculous request I've ever seen.

AutoIt isn't multi-threading, and even if it were, explain to me how something could be done at the same "exact" time... Never mind you can't... so quit bitching with suggestions (considering all you've done is shot down every attempt made) come up with some ideas of your own, switch languages, or learn how to use /AutoIt3ExecuteLine/Script.

Edit:

I should add:

Everything is registered one thing at a time... speed may make it seem like it was done simultaneously, but logic tells us something different.

Having said that, you may want to look at your send key delays.

Ignoring the urge to flame back, I have already looked at send key delays. I've tried it all, it does not work. I've "shot down" every attempt made because they HAVE NOT WORKED. I have then replied with WHY it does not seem to work, in an attempt to work the way towards something that DOES work.

Regarding your "most ridiculous request seen" comment, leading into how something can be done "at the same exact time". I dont know, how about Send("+1"), which sends a shift-1 command. Or does this, behind the scenes, send, essentially, shiftdown, 1, shiftup. I do not know, so I'm not going to throw this back at you.

Instead of being rude, you could actually help. But you did try and help, or so it seems, in the latter part of your reply. So in the end... I dont know.

Ultimately, this is a confusing problem, because of the following: If I manually press the keys "1" and "2" (just examples) at the 'same' time with my fingers (which we all know is not at the EXACT same time, and is indeed seperated by some time delay), the receiving program recognizes the notes as being played at the same time. However, if I use Send("12") or any of the above mentioned methods, including messing with the SendKeyDelay, the program still plays note 1, then note 2, and does not play them concurrently.

Link to comment
Share on other sites

  • Moderators

Ignoring the urge to flame back, I have already looked at send key delays. I've tried it all, it does not work. I've "shot down" every attempt made because they HAVE NOT WORKED. I have then replied with WHY it does not seem to work, in an attempt to work the way towards something that DOES work.

Regarding your "most ridiculous request seen" comment, leading into how something can be done "at the same exact time". I dont know, how about Send("+1"), which sends a shift-1 command. Or does this, behind the scenes, send, essentially, shiftdown, 1, shiftup. I do not know, so I'm not going to throw this back at you.

Instead of being rude, you could actually help. But you did try and help, or so it seems, in the latter part of your reply. So in the end... I dont know.

Ultimately, this is a confusing problem, because of the following: If I manually press the keys "1" and "2" (just examples) at the 'same' time with my fingers (which we all know is not at the EXACT same time, and is indeed seperated by some time delay), the receiving program recognizes the notes as being played at the same time. However, if I use Send("12") or any of the above mentioned methods, including messing with the SendKeyDelay, the program still plays note 1, then note 2, and does not play them concurrently.

Well, for what the flame was worth, I gave you the only answer to your problem that I can possibly see working....

AutoIt3ExecuteLine/Script.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Ultimately, this is a confusing problem, because of the following: If I manually press the keys "1" and "2" (just examples) at the 'same' time with my fingers (which we all know is not at the EXACT same time, and is indeed seperated by some time delay), the receiving program recognizes the notes as being played at the same time. However, if I use Send("12") or any of the above mentioned methods, including messing with the SendKeyDelay, the program still plays note 1, then note 2, and does not play them concurrently.

Have you tried increasing SendKeyDownDelay?

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

Maybe the program you are sending these key presses to is programmed to work naturally (human like) not the way you want it to. A more natural way of doing this is something like this. Give it a try.

This is actually what happens when you manually press the two keys down.

Opt("SendKeyDelay",0)
Opt("SendKeyDownDelay",0)

Send("{1 down}")
Sleep(20) ; normal delay for human like press, this delay is normally around (10 ~ 50) milliseconds, not 0...
Send("{2 down}")
Sleep(1000) Delay ;play both at same time for 1 second.
Send("{1 up}")
Sleep(20)
Send("{2 up}")

www.itoady.com

A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding

Link to comment
Share on other sites

I downloaded the trial music keyboard from www.kbdmusic.com

I can play a beautiful three note cord G J L with three fingers.

I have tried all the above suggestions (and a few of my own) but I can't replicate the cord.

I'm sure there must be a solution?

Edit - Warning - either kbdmusic.com software or one of my neverending loops but when both are running parts of my keyboard become dysfunctional, sometimes. Rebooting fixes my problem. Maybe the trial version wants to make sure you wont buy it?

If all the sounds of all the key combinations where say in a WAV/MP3 file then we could use Soundplay("GJL.wav") but that would be too easy.

Edited by 1905russell
Link to comment
Share on other sites

Modern 3D-accelerated video games can be somewhat resistant to automation. Either as a side-effect of the way they are programmed, or intentionally because the developers don't want you doing it. If your code works outside the game (e.g. in Notepad) but not inside, there's a good chance you've run into a brick wall.

On a different tack, the help file notes that using a value of 0 for SendKeyDelay sometimes doesn't work properly. Have you tried setting it to 1? Also try sending the two keys in one command, like "{1 DOWN}{2 DOWN}".

Link to comment
Share on other sites

I downloaded the trial music keyboard from www.kbdmusic.com

I can play a beautiful three note cord G J L with three fingers.

I have tried all the above suggestions (and a few of my own) but I can't replicate the cord.

I'm sure there must be a solution?

Works just fine:

Opt("SendKeyDelay", 0) 
Opt("SendKeyDownDelay", 0) 
HotKeySet("{PAUSE}", "GJL")
While 1
    sleep(100)
WEnd
Func GJL ()
    If WinActive("Keyboard Music") Then
        Send("{g DOWN}")
        Send("{j DOWN}")
        Send("{l DOWN}")
        Sleep(1000)
        Send("{l UP}")
        Send("{j UP}")
        Send("{g UP}")      
    EndIf
EndFunc
Edited by Siao

"be smart, drink your wine"

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...