Splitz Posted June 6, 2011 Share Posted June 6, 2011 Hello i'm a bit new to autoit, i want to make a script that pretty much does the following: When i press the "k" key, i want it to send {Space} and then {Space Down} and keep it held down until i lift my finger from the "k" key, at which point it will send the {Space Up} ... is this possible? Thanks! HotKeySet("k", "AH") HotKeySet("{F9}", "Terminate") Func AH() Send("{Space}") Sleep(50) Send("{Space down}") Sleep(?????) Send("{Space up}") EndFunc While 1 Sleep(500) WEnd Func Terminate() Exit 0 EndFunc Link to comment Share on other sites More sharing options...
GEOSoft Posted June 6, 2011 Share Posted June 6, 2011 See _IsPressed in the help file under User Defined Functions >> Misc Management It will be something like this (Not Tested) Func AH() Send("{Space}") Sleep(50) Send("{Space down}") While _IsPressed("4B") Sleep(100) WEnd Send("{Space up}") EndFunc George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Splitz Posted June 7, 2011 Author Share Posted June 7, 2011 (edited) with this code all that seems to be happening is, it spams space bar's really fast when i hold down k i'd like it to just <space> and then <space down> and only <space up> once i lift my finger from "k" #Include <Misc.au3> HotKeySet("{k}", "AH") HotKeySet("{F9}", "Terminate") Func AH() Send("{Space}") Sleep(50) Send("{Space down}") While _IsPressed("4B") Sleep(100) WEnd Send("{Space up}") EndFunc While 1 Sleep(500) WEnd Func Terminate() Exit 0 EndFunc Edited June 7, 2011 by Fenix` Link to comment Share on other sites More sharing options...
Maffe811 Posted June 7, 2011 Share Posted June 7, 2011 Why not just hold space down ? [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
Maffe811 Posted June 7, 2011 Share Posted June 7, 2011 This works for me:#include <Misc.au3> HotKeySet ("k", "Spacer") Func Spacer() If _IsPressed("4B") then Send("{SPACE}") EndIf EndFunc While 1 Sleep (40) WEnd [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
Splitz Posted June 7, 2011 Author Share Posted June 7, 2011 (edited) This script you made Maffe811 only does half of what i want, basically what i want to happen is this: when i press the "k" key and hold it down, i want the script to send a <space bar> press, and then i want it to wait about half a second or less, and then send a <space down> and once i lift my finger from the "k" key, it will send a <space up> Edited June 7, 2011 by Fenix` Link to comment Share on other sites More sharing options...
Maffe811 Posted June 7, 2011 Share Posted June 7, 2011 (edited) ... <space down> ... <space up>... After some reading... I dont belive thoose commands exist. #include <Misc.au3> HotKeySet ("k", "Spacer") Func Spacer() If _IsPressed("4B") then ;Input code when key is pressed. ElseIf Not _IsPressed("4B") Then ;Input code when key is released. EndIf EndFunc While 1 Sleep (40) WEndI could probably had an else instead of elseif... Edited June 7, 2011 by Maffe811 [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
GEOSoft Posted June 7, 2011 Share Posted June 7, 2011 After some reading... I dont belive thoose commands exist. To hold a key down (generally only useful for games) Send("{a down}") ;Holds the A key down Send("{a up}") ;Releases the A key Although he doesn't need the up/down really Func AH() HotKeySet("k") Send("{Space}") Sleep(100) ;Send("{Space down}") While _IsPressed("4B") Send("{SPACE}") WEnd ;Send("{Space up}") HotKeySet("{k}", "AH") EndFunc George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Maffe811 Posted June 7, 2011 Share Posted June 7, 2011 (edited) Didnt really work for me and then i missed the part you posted in the helpfile and those two combined led me to belive it couldnt be done. My bad I think i tried While _IsPressed but messed something up so it got stuck when i press the "k" key and hold it down, i want the script to send a <space bar> press, and then i want it to wait about half a second or less, and then send a <space down> and once i lift my finger from the "k" key, it will send a <space up> You could checkk how many times you could send space in half a second then use: Send ('{SPACE 30}') If there was enough time for 30 times in .5 of a second. ... #include <Misc.au3> HotKeySet ("k", "Spacer") Func Spacer() If _IsPressed("4B") then Send("{SPACE 30}") EndIf EndFunc While 1 Sleep (40) WEnd Edited June 7, 2011 by Maffe811 [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
GEOSoft Posted June 7, 2011 Share Posted June 7, 2011 Maffe811 You are missing something there just as I did in my first reply. The hotkey has to be unset when he first enters the function and reset on exit. Otherwise he will just keep calling the function again while k is held down. He wants to send a space then delay and then start sending spaces again while the key is down. And the timing idea is not good. By the way, this smacks of game code and you know where we stand on that. Of course that's just an opinion at this point. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Maffe811 Posted June 7, 2011 Share Posted June 7, 2011 Ah, i didnt quite understand but i see it now! Im wondering what this is for. @Fenix: Care to tell? [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now