Jump to content

hold a key to activate the script ?


r1se
 Share

Recommended Posts

  • Developers

Hey !

i want to hold f to activate my script, when i release the button f, the script should be paused.

regards

mmm second thread and not much progress.

This is an AutoIt3 support forum, not a script request forum.

So, start reading and researching first and come back when you have a real question.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Like Jos says, please search the forums or read the helpfile.

But, have fun...

GUICreate("Keypress example", 100, 40)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            Exit
    EndSwitch

    If _IsPressed(46) Then
        ToolTip("Running", 0,0)
    Else
        ToolTip("Not Running", 0,0)
    EndIf
WEnd

Func _IsPressed($hexKey)
    $hexKey = DllCall("user32", "int", "GetAsyncKeyState", "int", '0x' & $hexKey)
    If Not @error And BitAND($hexKey[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc  ;==>_IsPressed

Edit: Typo.

Edited by Miniz
Link to comment
Share on other sites

Hey !

i want to hold f to activate my script, when i release the button f, the script should be paused.

regards

Something like this i suppose.

#include <Misc.au3>
HotKeySet("f", "myFunction")

While 1
    Sleep(100)
WEnd

Func myFunction()
    If Not _IsPressed(46) Then Return
    While 1
        If Not _IsPressed(46) Then Return
        ConsoleWrite("F is still pressed" & @LF)
    WEnd
EndFunc   ;==>myFunction

EDIT:

actually that one aborts... not pauses...

Try this instead :-)

#include <Misc.au3>
HotKeySet("f", "myFunction")
HotKeySet("{ESC}", "_Exit")

While 1
    Sleep(100)
WEnd

Func myFunction()
    While 1
        _Pause() ;put this function before anything you do.
        ConsoleWrite("F is pressed" & @LF)
        Sleep(100)
    WEnd
EndFunc   ;==>myFunction

Func _Pause()
    If Not _IsPressed(46) Then ConsoleWrite("F released" & @LF)
    While Not _IsPressed(46)
        Sleep(100)
    WEnd
EndFunc   ;==>_Pause

Func _Exit()
    Exit
EndFunc   ;==>_Exit
Edited by Djarlo
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...