Jump to content
Sign in to follow this  
Sykotron

Help on simple Sends and DllCall

Recommended Posts

Sykotron

I just started work at a place where we were issued a laptop. We do not have admin privileges and the power-saving options put the computer into standby absurdly quickly as well as user account locking due to inactivity. I understand this is likely against their wishes, but I'm working on a script that prevents these. There are also many places where typing user information is required which I'd like to automate. Currently when I press my hotkey to type my user information in it has some unwanted effects. It seems it holds down the hotkey key indefinitely until I manually press it myself (i.e. I press CTRL+= and afterwards I must press CTRL in order to do most anything). I'm trying to simply send the up stroke of the key and blocking user input, but I'm still having issues. Our print screen key is physically disabled but it's copy the screen to the clipboard functionality isn't so I've got a key set up for that.

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused
Global $USERNAME = "removed"
Global $ZID = "removed"
Global $PASSWORD = "removed"
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("!-", "Terminate")  ;Alt--
HotKeySet("!=", "Login")  ;Alt-=
HotKeySet("^=", "LoginZ") ;Ctrl-=
HotKeySet("{SCROLLLOCK}", "SS")

;;;; Body of program would go here ;;;;
DllCall("kernel32.dll", "DWORD", "SetThreadExecutionState", "DWORD", 2147483651)
While 1
    BlockInput(1)
    Send("{CTRLUP}")
    BlockInput(0)
        Sleep(120000)
    BlockInput(1)
    Send("{PRINTSCREEN}")
    Send("{CTRLUP}")
    BlockInput(0)
WEnd
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func Login()
    BlockInput(1)
    Send("{CTRLUP}")
    Sleep(500)
        Send($USERNAME)
    Send("{TAB}")
    Send($PASSWORD)
    Sleep(200)
    Send("{CTRLUP}")
    BlockInput(0)
EndFunc

Func LoginZ()
    BlockInput(1)
    Send("{CTRLUP}")
    Sleep(500)
    Send($ZID)
    Send("{TAB}")
    Send($PASSWORD)
    Sleep(200)
    Send("{CTRLUP}")
    BlockInput(0)
EndFunc

Func SS()
    BlockInput(1)
    Send("{CTRLUP}")
    Send("{PRINTSCREEN}")
    Send("{CTRLUP}")
    BlockInput(0)
EndFunc

Share this post


Link to post
Share on other sites
Bert

The problem is this:

While 1

BlockInput(1)

Send("{CTRLUP}")

BlockInput(0)

Sleep(120000)

BlockInput(1)

Send("{PRINTSCREEN}")

Send("{CTRLUP}")

BlockInput(0)

WEnd

Your loop is in need of some love here. If anything you should simply have an idle loop and then call your functions on demand.

Share this post


Link to post
Share on other sites
Sykotron

Well this is the idle loop that should be running continuously. I want it to hit a key once every 2 minutes to make sure I don't go idle and get logged out/locked. Maybe I don't understand what you're saying though?

Share this post


Link to post
Share on other sites
KaFu

Here's an alternative method that worked for me :mellow: ... maybe set the sleep even to 10.000 or 60.000 or something like that, then it shouldn't even bother you while working...

Edit: Using _Timer_GetIdleTime() might even make it leaner :)...

#include <Timers.au3>

HotKeySet("{ESC}", "_Exit")
Global $i

While Sleep(500)
    If _Timer_GetIdleTime() > 30000 Then
        $i += 1
        $aMousePos = MouseGetPos()
        Switch Mod($i, 2)
            Case True
                MouseMove($aMousePos[0] + 1, $aMousePos[1])
            Case False
                MouseMove($aMousePos[0] - 1, $aMousePos[1])
        EndSwitch
    EndIf
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit
Edited by KaFu

Share this post


Link to post
Share on other sites
Sykotron

Here's an alternative method that worked for me :mellow: ... maybe set the sleep even to 10.000 or 60.000 or something like that, then it shouldn't even bother you while working...

Edit: Using _Timer_GetIdleTime() might even make it leaner :)...

#include <Timers.au3>

HotKeySet("{ESC}", "_Exit")
Global $i

While Sleep(500)
    If _Timer_GetIdleTime() > 30000 Then
        $i += 1
        $aMousePos = MouseGetPos()
        Switch Mod($i, 2)
            Case True
                MouseMove($aMousePos[0] + 1, $aMousePos[1])
            Case False
                MouseMove($aMousePos[0] - 1, $aMousePos[1])
        EndSwitch
    EndIf
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

This isn't my main issue. The anti-idling seems to be working just fine. I'm concerned because some keys are getting "stuck"... unless this is all related to that I press print screen once every two minutes which I could easily change to move the mouse by 1 pixel and back. Also, what are some suggestions of keys that do nothing in other applications that I can use as hotkeys.

Share this post


Link to post
Share on other sites
KaFu

Take a look here: http://www.autoitscript.com/wiki/FAQ#Keys_virtually_stuck

And something like HotKeySet("!+^#f","_Func") should be quite save to use :mellow:.

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.