Jump to content
Sign in to follow this  
martinandersen3d

[Solved] Autoit: Keys Win+left, Win+right, Win+Up, Win+Down

Recommended Posts

martinandersen3d

Just want to share this code, where you can register Win Keys + any combination, including Win+left, Win+right, Win+Up, Win+Down.

 I tryed looking around on the forum and did not find any simelar. Normaly you use the: HotKeySet("#{PGUP}", "WindowsDesktopLeft")

to register keys, but I could not get it to work with window+arrow keys. So here is a solution.

 

You can disable windows default behavior for Windows+arrows in:  Windows 10 settings > System > Multitasking, and disable Snap.

 

My current goal was to get these keys/action:

win+left = virtual desktop left

win+right = virtual desktop right

win+n = New virtual desktop 

win+f4 = Close current virtual desktop 

 

Enjoy :-)

 

;~ See list of keys to detect here
;~ https://www.autoitscript.com/autoit3/docs/libfunctions/_IsPressed.htm
#include <Misc.au3>
#include <MsgBoxConstants.au3>

Local $hDLL = DllOpen("user32.dll")

Func lWinKeyPressed()
    If (_IsPressed("5B", $hDLL)) Then
        Return True
    EndIf
EndFunc

Func rWinKeyPressed()
    If (_IsPressed("5C", $hDLL)) Then
        Return True
    EndIf
EndFunc


Func leftKeyPressed()
    If (_IsPressed("25", $hDLL)) Then
        Return True
    EndIf
EndFunc

Func rightKeyPressed()
    If (_IsPressed("27", $hDLL)) Then
        Return True
    EndIf
EndFunc

Func upKeyPressed()
    If (_IsPressed("26", $hDLL)) Then
        Return True
    EndIf
EndFunc

Func downKeyPressed()
    If (_IsPressed("27", $hDLL)) Then
        Return True
    EndIf
EndFunc

Func spaceKeyPressed()
    If (_IsPressed("20", $hDLL)) Then
        Return True
    EndIf
EndFunc

Func altKeyPressed()
    If (_IsPressed("12", $hDLL)) Then
        Return True
    EndIf
EndFunc

Func ctrlKeyPressed()
    If (_IsPressed("11", $hDLL)) Then
        Return True
    EndIf
EndFunc

Func shiftKeyPressed()
    If (_IsPressed("10", $hDLL)) Then
        Return True
    EndIf
EndFunc

Func winKeyPressed()
    If ( lWinKeyPressed() Or rWinKeyPressed() ) Then
        Return True
    EndIf
EndFunc

Func win_left()
    If ( winKeyPressed() And leftKeyPressed() ) Then
        Return True
    EndIf
EndFunc

Func win_right()
    If ( winKeyPressed() And rightKeyPressed() ) Then
        Return True
    EndIf
EndFunc

While 1

    If win_left() Then
        ; Code: When keyes are pressed.
        ConsoleWrite("Win+left Key is pressed." & @CRLF)
        While win_left()
             Sleep(50)
        WEnd
        ; Code: When keyes are released.
        ConsoleWrite("Win+left Key is released." & @CRLF)

    ElseIf win_right() Then
        ; Code: When keyes are pressed.
        ConsoleWrite("Win+right Key is pressed." & @CRLF)
        While win_right()
             Sleep(50)
        WEnd
        ; Code: When keyes are released.
        ConsoleWrite("Win+right Key is released." & @CRLF)
    EndIf
    ;~ Sleep(250)
WEnd




DllClose($hDLL)

 

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  

×