Git Product home page Git Product logo

Comments (10)

FuPeiJiang avatar FuPeiJiang commented on July 27, 2024 1

I can think of 2 ways:

*1::
*2::
*3::
*4::
*5::
*6::
*7::
*8::
*9::
    numeric:=SubStr(A_ThisHotkey,2,1)
    KeyWait % numeric, T0.5
    If ErrorLevel = 1
    {
    Soundbeep, 1500
    VD.MoveWindowToDesktopNum("A", numeric)
    KeyWait % numeric
    }
    Else Send % numeric
Return
*1::foo("1")
*2::foo("2")
*3::foo("3")
*4::foo("4")
*5::foo("5")
*6::foo("6")
*7::foo("7")
*8::foo("8")
*9::foo("9")
foo(numeric) {
    KeyWait % numeric, T0.5
    If ErrorLevel = 1
    {
    Soundbeep, 1500
    VD.MoveWindowToDesktopNum("A", numeric)
    KeyWait % numeric
    }
    Else Send % numeric
}

one downside of my code is that I'm able to notice latency with typing numbers.

numbers are sent on KeyUp, instead of the default: on KeyDown

if any other key is pressed while a number is down(like when typing), you might want to send the number immediately, but I don't immediately know how to code that

from vd.ahk.

xav-ie avatar xav-ie commented on July 27, 2024

You need to check that C:\Ahk\Library\VD.ahk file exists first. It probably does not. You need to make sure you put repo in AutoHotkey folder or wherever you keep AutoHotkey scripts. Your code is not relevant yet until you first fix your sourcing issue

from vd.ahk.

FuPeiJiang avatar FuPeiJiang commented on July 27, 2024

copy SetForeGroundWindow.exe into C:\Ahk\Library\, it needs to be in the same folder as VD.ahk


When I run the folloinwg code, it returns empty message box.

what is your windows version ? what is the value of A_OSVersion ? :

MsgBox % Clipboard:=A_OSVersion

My goal is to create a code when I activate a window with mouse left click, I can just go to the virtual desktop I desire

what is the code for LButton ? you've only sent the code for MButton

LButton::
???

from vd.ahk.

TaroDumpling avatar TaroDumpling commented on July 27, 2024
MsgBox % Clipboard:=A_OSVersion

I moved SetForeGroundWindow.exe to where VD.ahk is, same issue. I'm actually using _VD.ahk, but I renamed it as VD.ahk, could that be a problem? My version is 10.0.22621. As for LButton, there is no code for it. It's just when you click on an application, it activates that window. So I was thinking once I activated it, I can just go to another virtual desktop, and middle click on the desktop to bring that previously activated window to the new virtual desktop. Thanks for trying to help.

from vd.ahk.

TaroDumpling avatar TaroDumpling commented on July 27, 2024

You need to check that C:\Ahk\Library\VD.ahk file exists first. It probably does not. You need to make sure you put repo in AutoHotkey folder or wherever you keep AutoHotkey scripts. Your code is not relevant yet until you first fix your sourcing issue

VD.ahk does exist in C:\Ahk\Library, and the scripts I have included previously have been working just fine. So I doubt that was the problem. But just in case, below is how I included my scripts:

#Include C:\Ahk\Library\
#Include Class_NvAPI.ahk
#Include FindText.ahk
#Include desktop_switcher.ahk
#Include RegionWaitChange.ahk
#Include VA.ahk
#Include VD.ahk

from vd.ahk.

FuPeiJiang avatar FuPeiJiang commented on July 27, 2024

I'm actually using _VD.ahk, but I renamed it as VD.ahk

then you need to add 1 line:

VD.init()

so it becomes (please don't rename it, keep it as _VD.ahk):

#Include %A_LineFile%\..\..\_VD.ahk
VD.init()

foundProcesses := ""
; Make sure to get all windows from all virtual desktops
DetectHiddenWindows On
WinGet, id, List
Loop %id%
{
    hwnd := id%A_Index%
    ;VD.getDesktopNumOfWindow will filter out invalid windows
    desktopNum_ := VD.getDesktopNumOfWindow("ahk_id" hwnd)
    If (desktopNum_ > -1) ;-1 for invalid window, 0 for "Show on all desktops", 1 for Desktop 1
    {
        WinGet, exe, ProcessName, % "ahk_id" hwnd
        foundProcesses .= desktopNum_ " " exe "`n"
    }
}

MsgBox % foundProcesses

if you #Include _VD.ahk, you have to call VD.init()
if you #Include VD.ahk, it will #Include _VD.ahk and call VD.init() for you
that's the difference between the 2 files.

from vd.ahk.

TaroDumpling avatar TaroDumpling commented on July 27, 2024

I'm actually using _VD.ahk, but I renamed it as VD.ahk

then you need to add 1 line:

VD.init()

so it becomes (please don't rename it, keep it as _VD.ahk):

#Include %A_LineFile%\..\..\_VD.ahk
VD.init()

foundProcesses := ""
; Make sure to get all windows from all virtual desktops
DetectHiddenWindows On
WinGet, id, List
Loop %id%
{
    hwnd := id%A_Index%
    ;VD.getDesktopNumOfWindow will filter out invalid windows
    desktopNum_ := VD.getDesktopNumOfWindow("ahk_id" hwnd)
    If (desktopNum_ > -1) ;-1 for invalid window, 0 for "Show on all desktops", 1 for Desktop 1
    {
        WinGet, exe, ProcessName, % "ahk_id" hwnd
        foundProcesses .= desktopNum_ " " exe "`n"
    }
}

MsgBox % foundProcesses

if you #Include _VD.ahk, you have to call VD.init() if you #Include VD.ahk, it will #Include _VD.ahk and call VD.init() for you that's the difference between the 2 files.

Thank you so much, this fixed it!

from vd.ahk.

FuPeiJiang avatar FuPeiJiang commented on July 27, 2024

So I was thinking once I activated it, I can just go to another virtual desktop, and middle click on the desktop to bring that previously activated window to the new virtual desktop.

VD.MoveWindowToCurrentDesktop("A")

when you go to another virtual desktop, the active window changes to a window on the VD you go to, (the active windows is literally what you are seeing in front of you), so this will bring the current active window to the current desktop, doing nothing

so you will have to save the last active window in another VD somehow, (save the hwnd of that window)
then:

VD.MoveWindowToCurrentDesktop("ahk_id " savedHwnd)

@TaroDumpling
this works for the simple of cases, I need bug testing (it doesn't always activate, but I need to know the precise steps that make it not activate)

middle click bring other vd active window.ahk:

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
ListLines Off
SetBatchLines -1
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#KeyHistory 0
#WinActivateForce

Process, Priority,, H

#Include %A_LineFile%\..\..\VD.ahk

SetWinDelay -1
SetControlDelay -1

DllCall("RegisterShellHookWindow","Ptr",A_ScriptHwnd)
OnMessage(DllCall("RegisterWindowMessage",Str,"SHELLHOOK"), "ShellMessage")

VD.RegisterDesktopNotifications()
VD.CurrentVirtualDesktopChanged:=Func("CurrentVirtualDesktopChanged")
CurrentVirtualDesktopChanged(desktopNum_Old, desktopNum_New) {
    global other_VD_hwnd, current_VD_Hwnd
    other_VD_hwnd:=current_VD_Hwnd
    current_VD_Hwnd:=false
}

current_VD_Hwnd:=WinExist("A")

#If MouseIsOver("ahk_class Progman ahk_exe explorer.exe")

MButton::
if (other_VD_hwnd) {
    VD.MoveWindowToCurrentDesktop("ahk_id " other_VD_hwnd)
}
return

#If

MouseIsOver(WinTitle) {
    MouseGetPos,,, Win
    return WinExist(WinTitle) == Win
}

Return

ShellMessage(wParam,lParam) {
    global current_VD_Hwnd
    switch wParam {
        case 2, 4, 32772:
            ; WinGetTitle, title, ahk_id %lParam%
            ; ToolTip WinActivated`n%Title%
            if (lParam) {
                current_VD_Hwnd:=lParam
            }
        ; default:
            ; ToolTip % wParam
    }
}

f3::Exitapp

from vd.ahk.

TaroDumpling avatar TaroDumpling commented on July 27, 2024

So I was thinking once I activated it, I can just go to another virtual desktop, and middle click on the desktop to bring that previously activated window to the new virtual desktop.

VD.MoveWindowToCurrentDesktop("A")

when you go to another virtual desktop, the active window changes to a window on the VD you go to, (the active windows is literally what you are seeing in front of you), so this will bring the current active window to the current desktop, doing nothing

so you will have to save the last active window in another VD somehow, (save the hwnd of that window) then:

VD.MoveWindowToCurrentDesktop("ahk_id " savedHwnd)

@TaroDumpling this works for the simple of cases, I need bug testing (it doesn't always activate, but I need to know the precise steps that make it not activate)

middle click bring other vd active window.ahk:

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
ListLines Off
SetBatchLines -1
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#KeyHistory 0
#WinActivateForce

Process, Priority,, H

#Include %A_LineFile%\..\..\VD.ahk

SetWinDelay -1
SetControlDelay -1

DllCall("RegisterShellHookWindow","Ptr",A_ScriptHwnd)
OnMessage(DllCall("RegisterWindowMessage",Str,"SHELLHOOK"), "ShellMessage")

VD.RegisterDesktopNotifications()
VD.CurrentVirtualDesktopChanged:=Func("CurrentVirtualDesktopChanged")
CurrentVirtualDesktopChanged(desktopNum_Old, desktopNum_New) {
    global other_VD_hwnd, current_VD_Hwnd
    other_VD_hwnd:=current_VD_Hwnd
    current_VD_Hwnd:=false
}

current_VD_Hwnd:=WinExist("A")

#If MouseIsOver("ahk_class Progman ahk_exe explorer.exe")

MButton::
if (other_VD_hwnd) {
    VD.MoveWindowToCurrentDesktop("ahk_id " other_VD_hwnd)
}
return

#If

MouseIsOver(WinTitle) {
    MouseGetPos,,, Win
    return WinExist(WinTitle) == Win
}

Return

ShellMessage(wParam,lParam) {
    global current_VD_Hwnd
    switch wParam {
        case 2, 4, 32772:
            ; WinGetTitle, title, ahk_id %lParam%
            ; ToolTip WinActivated`n%Title%
            if (lParam) {
                current_VD_Hwnd:=lParam
            }
        ; default:
            ; ToolTip % wParam
    }
}

f3::Exitapp

I figured out an easier and more practical solution. I want to do the same thing using hotkey 1 through 9. Are there ways to make my code shorter instead of write the code for hotkey 1, hotkey 2, hotkey 3, and so forth? I wanted to not send numbers when I'm long pressing, one downside of my code is that I'm able to notice latency with typing numbers. Thanks!

;  Move Window to Desktop by Long Pressing number 1 to 9.
      *1::
         KeyWait, 1, T0.5
         If ErrorLevel = 1
         {
            Soundbeep, 1500
            VD.MoveWindowToDesktopNum("A", 1)
            KeyWait, 1
         }
         Else Send {1}
      Return

      *2::
         KeyWait, 2, T0.5
         If ErrorLevel = 1
         {
            Soundbeep, 1500
            VD.MoveWindowToDesktopNum("A", 2)
            KeyWait, 2
         }
         Else Send {2}
      Return

from vd.ahk.

TaroDumpling avatar TaroDumpling commented on July 27, 2024

I can think of 2 ways:

*1::
*2::
*3::
*4::
*5::
*6::
*7::
*8::
*9::
    numeric:=SubStr(A_ThisHotkey,2,1)
    KeyWait % numeric, T0.5
    If ErrorLevel = 1
    {
    Soundbeep, 1500
    VD.MoveWindowToDesktopNum("A", numeric)
    KeyWait % numeric
    }
    Else Send % numeric
Return
*1::foo("1")
*2::foo("2")
*3::foo("3")
*4::foo("4")
*5::foo("5")
*6::foo("6")
*7::foo("7")
*8::foo("8")
*9::foo("9")
foo(numeric) {
    KeyWait % numeric, T0.5
    If ErrorLevel = 1
    {
    Soundbeep, 1500
    VD.MoveWindowToDesktopNum("A", numeric)
    KeyWait % numeric
    }
    Else Send % numeric
}

one downside of my code is that I'm able to notice latency with typing numbers.

numbers are sent on KeyUp, instead of the default: on KeyDown

if any other key is pressed while a number is down(like when typing), you might want to send the number immediately, but I don't immediately know how to code that

I really appreciate the advice, thank you so much!

from vd.ahk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.