Jump to content

Key press


Oreoleo
 Share

Recommended Posts

Hey, I'm new to autoit.

I've been trying to code something where, I could press a button, for example 4, and it would send it every 15ms. I would keep the button pressed and it would keep sending it, until I stop pressing it.

This is as far as I've gotten, but it won't do the trick because it would just keep queuing it if I don't let off the button.

HotKeySet("4", "Fi")
Func Fi()
For $i = 1 To 15 Step 1
sleep(15)
Send("4")
Next
EndFunc

Help would be greatly appreciated!

Thanks, cya

Link to comment
Share on other sites

Hey, I'm new to autoit.

I've been trying to code something where, I could press a button, for example 4, and it would send it every 15ms. I would keep the button pressed and it would keep sending it, until I stop pressing it.

This is as far as I've gotten, but it won't do the trick because it would just keep queuing it if I don't let off the button.

HotKeySet("4", "Fi")
Func Fi()
For $i = 1 To 15 Step 1
sleep(15)
Send("4")
Next
EndFunc

Help would be greatly appreciated!

Thanks, cya

Welcome to the AutoIt forums :D

You could have 2 hotkeys. One to start send the key and one to stop.

If you want to send "4" then you can't use 4 for the HotKey because it will just trigger the Fi function again.

HotKeySet("{F1}","Fi")
HotKeySet("{F2}","Fo")
HotKeySet("{ESC}","GO_OUT")
Global $stay = true

while 1
 Sleep(20)  
WEnd


Func Fi()
 while $stay
  Send("4")
  sleep(100)
 wend

endfunc

Func Fo()
 $stay = false
endfunc

Func GO_Out()
    Exit
EndFunc
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

@martin your script is almost what I was looking for. Just wondering if there was a way for say an F3 button to restart the script instead of having to Go_out and then re-opening the au3 file.

I tried this but it didn't work

HotKeySet("{F1}","Fi")
HotKeySet("{F2}","Fo")
HotKeySet("{ESC}","GO_OUT")
HotKeySet("(F3)","Restart")
Global $stay = true

while 1
Sleep(20)   
WEnd


Func Fi()
while $stay
  Send("4")
  sleep(1000)
wend

endfunc

Func Fo()
$stay = false
endfunc

Func GO_Out()
    Exit
EndFunc

Func Restart()
    Run("haha.au3")
Endfunc
Link to comment
Share on other sites

@martin your script is almost what I was looking for. Just wondering if there was a way for say an F3 button to restart the script instead of having to Go_out and then re-opening the au3 file.

I tried this but it didn't work

HotKeySet("{F1}","Fi")
HotKeySet("{F2}","Fo")
HotKeySet("{ESC}","GO_OUT")
HotKeySet("(F3)","Restart")
Global $stay = true

while 1
Sleep(20)   
WEnd


Func Fi()
while $stay
  Send("4")
  sleep(1000)
wend

endfunc

Func Fo()
$stay = false
endfunc

Func GO_Out()
    Exit
EndFunc

Func Restart()
    Run("haha.au3")
Endfunc
Try this, but before using compile script:

HotKeySet("{F1}","Fi")
HotKeySet("{F2}","Fo")
HotKeySet("{ESC}","GO_OUT")
HotKeySet("{F3}","Restart")

Global $stay = true

while 1
Sleep(20)    
WEnd


Func Fi()
while $stay
  Send("4")
  sleep(1000)
wend

endfunc

Func Fo()
$stay = false
endfunc

Func GO_Out()
    Exit
EndFunc

Func Restart()
    ShellExecute(@ScriptFullPath)
    Exit
Endfunc
Link to comment
Share on other sites

@martin your script is almost what I was looking for. Just wondering if there was a way for say an F3 button to restart the script instead of having to Go_out and then re-opening the au3 file.

I tried this but it didn't work

HotKeySet("{F1}","Fi")
HotKeySet("{F2}","Fo")
HotKeySet("{ESC}","GO_OUT")
HotKeySet("(F3)","Restart")
Global $stay = true

while 1
Sleep(20)   
WEnd


Func Fi()
while $stay
  Send("4")
  sleep(1000)
wend

endfunc

Func Fo()
$stay = false
endfunc

Func GO_Out()
    Exit
EndFunc

Func Restart()
    Run("haha.au3")
Endfunc
What do you want to happen. If you restart then there is no point in ending the script first so I suspect I don't understand your question.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...