请教大家一个函数的写法 Topic is solved

遇到了问题?请先进行搜索(中文和英文),然后在此提问

Moderators: tmplinshi, arcticir

AAHKUser
Posts: 21
Joined: 19 Jun 2020, 04:31

请教大家一个函数的写法

30 Dec 2021, 07:05

各位高手,大家好〜

想请教大家下面的这段代码如何用函数的方式实现,因为涉及到许多按键的同样方式的替换,所以我想用函数的方式来重写这段代码,但我自己尝试总不成功。

Code: Select all

:*:n::
If (A_CaretX  > 0){
	if GetKeyState("Shift"){
	sendinput, N
	}
	else{
		sendinput, n
		}  
	}
else{
sendinput, ^+n
}
return
我自己写的函数如下,不知为何失败,希望能得到各位指点,谢谢!

Code: Select all

:*:n::   ; 一键N新建文件夹
GetTheKey(n, ^+n) 
return

GetTheKey(TheKey, TheFunc) 

Str :=TheKey
SringUpper, String2, Str
	if (A_CaretX  > 0){
		if GetKeyState("Shift"){
			SendInput, %String2%
		}
		else{
			SendInput, %TheKey%
		}
	}
	else{
		SendInput, %TheFunc%
	}

[Mod edit: [code][/code] tags added.]
fwejifjjwk2
Posts: 89
Joined: 10 Aug 2019, 01:49

Re: 请教大家一个函数的写法  Topic is solved

01 Jan 2022, 16:21

我這裡寫 ahk v2 的代碼,給你參考。
我把你另外一篇「模仿mac系统的回车重命名」的需求也合併進來了,創建上下文相關的熱鍵和熱字串很適合用在這裡。

Code: Select all

#HotIf (WinActive("ahk_exe Explorer.EXE")) and (not CaretGetPos(&x, &y))
; 新資料夾
:*:n::
{
	Send "^+n"
}

; 重新命名
$enter::
{
	Send "{F2}"
}
#HotIf
AAHKUser
Posts: 21
Joined: 19 Jun 2020, 04:31

Re: 请教大家一个函数的写法

01 Jan 2022, 21:26

fwejifjjwk2 wrote:
01 Jan 2022, 16:21
我這裡寫 ahk v2 的代碼,給你參考。
我把你另外一篇「模仿mac系统的回车重命名」的需求也合併進來了,創建上下文相關的熱鍵和熱字串很適合用在這裡。

Code: Select all

#HotIf (WinActive("ahk_exe Explorer.EXE")) and (not CaretGetPos(&x, &y))
; 新資料夾
:*:n::
{
	Send "^+n"
}

; 重新命名
$enter::
{
	Send "{F2}"
}
#HotIf
非常感谢!真的从您这里学到了非常多技巧!

Return to “请求帮助”

Who is online

Users browsing this forum: No registered users and 16 guests