Jump to content

Help on simple Sends and DllCall


Recommended Posts

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

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.

Link to comment
Share on other sites

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

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.
Link to comment
Share on other sites

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...