Jump to content

Not Working: send / _WinAPI_Keybd_Event


Recommended Posts

Hello,

 

in Windows is an option, that let you move your cursor with the numeric keypad. i  set it up and it works, when i press the numeric keys on my physical keyboard then my cursor moves.    but if i try to  do it via autoit  for example

 

send ("

{NUMPAD8}

")

 

instead the cursor is moving, a 8 was typed. so whats wrong here? shouldnt it be the same as the physical  keystroke?

Link to comment
Share on other sites

  • Moderators

@hessebou you can probably do this with hotkeyset, but can you please explain more about what you are trying to accomplish? There is undoubtedly a better way.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I don't think he wants to move mouse but move carret.  I tested it and it is true that it will send an 8 no matter what numlock is.  Not sure but it might be considered as a bug...

Link to comment
Share on other sites

Look at HotKey UDF here

 

Or you can use keybd_event directly through DllCall like in this example:

#Include 'HotKey.au3'
#Include 'vkConstants.au3'

HotKeySet('{Esc}', '_Quit')
_HotKeyAssign(BitOR($CK_WIN, $VK_L), 'ScreenSaver')

While 1
    Sleep(10)
WEnd

Func ScreenSaver()
    Local Const $SC_SCREENSAVE = 0xF140
    Local $Timer = TimerInit()
    DllCall('user32.dll', 'int', 'LockWorkStation')
    Do
        Sleep(10)
        If TimerDiff($Timer) > 1000 Then
            Return
        EndIf
    Until _IsWorkstationLocked()
    _SendMessage(_WinAPI_GetDesktopWindow(), $WM_SYSCOMMAND, $SC_SCREENSAVE, 0)
    While _IsWorkstationLocked()
        Sleep(10)
    WEnd
    DllCall('user32.dll', 'int', 'keybd_event', 'int', $VK_L, 'int', 0, 'int', 2, 'ptr', 0)
    DllCall('user32.dll', 'int', 'keybd_event', 'int', $VK_LWIN, 'int', 0, 'int', 2, 'ptr', 0)
    DllCall('user32.dll', 'int', 'keybd_event', 'int', $VK_RWIN, 'int', 0, 'int', 2, 'ptr', 0)
EndFunc   ;==>ScreenSaver

Func _IsWorkstationLocked()
    Local Const $DESKTOP_SWITCHDESKTOP = 0x0100
    Local $Result = False
    $hDesktop = DllCall('user32.dll', 'hwnd', 'OpenDesktop', 'str', 'Default', 'int', 0, 'int', 0, 'int', $DESKTOP_SWITCHDESKTOP)
    If Not @error Then
        $Result = DllCall('user32.dll', 'int', 'SwitchDesktop', 'hwnd', $hDesktop[0])
        $Result = Not $Result[0]
        DllCall('user32.dll', 'int', 'CloseDesktop', 'hwnd', $hDesktop[0])
    EndIf
    Return $Result
EndFunc   ;==>_IsWorkstationLocked

Func _Quit()
    Exit
EndFunc   ;==>_Quit

 

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