Comments (10)
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.
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.
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.
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.
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 inAutoHotkey
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.
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.
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 % foundProcessesif you #Include
_VD.ahk
, you have to callVD.init()
if you #IncludeVD.ahk
, it will #Include_VD.ahk
and callVD.init()
for you that's the difference between the 2 files.
Thank you so much, this fixed it!
from vd.ahk.
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.
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.
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)
- After pinning with AH2 version, I get an error when switching desktops by number.
- Script sending "Q" to discord | Desktop switch failure. HOT 2
- getDesktopNumOfWindow sometimes returns -1 rather than the correct num HOT 4
- open Application directly on one virtual desktop in background HOT 2
- "Error: (0x80004002) No such interface supported" after updating Windows 11 (Beta insider channel) HOT 13
- sending keypress to specified virtual desktop only.
- Ah2: Desktop Looping & Switching + Other Feature Regression from Commit ee2f54f626914273f00853306c1daaf803f756cb HOT 2
- It doesn't work on Windows 11 Build 22621.2215 (22H2) HOT 2
- A problem with the new Windows update 11 HOT 18
- Virtual desktop Tasksbar icons HOT 4
- renaming desktops HOT 1
- Switching to Relative Desktop fails initially HOT 2
- Current desktop count is always zero
- New Windows Build 23606: VD.getCurrentDesktopNum() always returns 0 HOT 4
- Windows Server 2022 version HOT 3
- It doesn't work on Windows 11 Build 22631.3085 (23H2) HOT 13
- v2_port分支没有 TogglePinApp,PinApp,UnPinApp HOT 2
- WinExist in another virtual desktop HOT 7
- Previous Desktop HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vd.ahk.