如何实现多层键盘切换? Topic is solved

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

Moderators: tmplinshi, arcticir

g1879

如何实现多层键盘切换?

Post by g1879 » 15 Nov 2019, 03:12

我想实现一个功能,双击alt,把字母区左边映射为数字,jkli等几个键映射为方向键,再次双击alt取消。
请问如何实现?谢谢。

fwejifjjwk2
Posts: 89
Joined: 10 Aug 2019, 01:49

Re: 如何实现多层键盘切换?

Post by fwejifjjwk2 » 15 Nov 2019, 06:28

Code: Select all

Index = 0

intInterval := 500
~LControl::
    if (A_PriorHotkey <> "~LControl" or A_TimeSincePriorHotkey > intInterval)
    {
        KeyWait, LControl
        return
    }
    Else {
        if (Index = 1 ){
            EnvAdd, Index ,-1
        }
        Else {
            EnvAdd, Index ,1
        }
    }
return

#if (Index = 1)
    
j::Down
k::Up
h::Left
l::Right
#if ; End #if


Last edited by fwejifjjwk2 on 05 Apr 2021, 20:38, edited 3 times in total.

tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: 如何实现多层键盘切换?  Topic is solved

Post by tmplinshi » 15 Nov 2019, 08:58

Code: Select all

~Alt::IsDoubleClick() ? (RemapKeys := !RemapKeys) : ""

#If RemapKeys
	j::Left
	l::Right
	i::Up
	k::Down
#If

IsDoubleClick() {
	static doubleClickTime := DllCall("GetDoubleClickTime")
	KeyWait, % LTrim(A_ThisHotkey, "~")
	return (A_ThisHotKey = A_PriorHotKey) && (A_TimeSincePriorHotkey <= doubleClickTime)
}

Guest

Re: 如何实现多层键盘切换?

Post by Guest » 15 Nov 2019, 10:28

非常感谢

Guest

Re: 如何实现多层键盘切换?

Post by Guest » 15 Nov 2019, 11:33

tmplinshi wrote:
15 Nov 2019, 08:58

Code: Select all

~Alt::IsDoubleClick() ? (RemapKeys := !RemapKeys) : ""

#If RemapKeys
	j::Left
	l::Right
	i::Up
	k::Down
#If

IsDoubleClick() {
	return (A_ThisHotKey = A_PriorHotKey) && (A_TimeSincePriorHotkey <= DllCall("GetDoubleClickTime"))
}
感谢。我还想实现双击alt后在屏幕左上角显示一个半透明的符号,处于最高层,用来指示当前状态,再次双击消失。请问该如何做?谢谢。

fwejifjjwk2
Posts: 89
Joined: 10 Aug 2019, 01:49

Re: 如何实现多层键盘切换?

Post by fwejifjjwk2 » 15 Nov 2019, 23:31

Code: Select all

keyboard_state = 0

intInterval := 300
~LAlt::
    if (A_PriorHotkey <> "~LAlt" or A_TimeSincePriorHotkey > intInterval)
    {
        KeyWait, LAlt
        return
    }
    Else {
        if (keyboard_state = 1 ){
            EnvAdd, keyboard_state ,-1
            Gui,Destroy
        }
        Else {
             EnvAdd, keyboard_state ,1
            ;SoundBeep, 200, 300
            showtext(1)
        }
    }
return

#if (keyboard_state = 1)
    
	j::Left
	l::Right
	i::Up
	k::Down
#if ; End #if
    

showtext(str)
{
    x := 10
    y := 10
    Gui,Destroy
    Gui,+AlwaysOnTop +Disabled -Caption -SysMenu +Owner +LastFound
    WinGet,hwnd,ID
    Gui, font, s26 ECF3F7 w600, Verdana
    Gui, Color, ECF3F7
    WinSet, TransColor, ECF3F7
    Gui,Add,Text,BackgroundTrans,%str%
    Gui, Show, NoActivate Y%y% X%x% NA, Title of Window
}

Last edited by fwejifjjwk2 on 05 Apr 2021, 20:37, edited 3 times in total.

tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: 如何实现多层键盘切换?

Post by tmplinshi » 16 Nov 2019, 11:28

楼主应该是想要显示一个背景色半透明的窗口,我多提供一个代码吧。

Code: Select all

~Alt::
	if IsDoubleClick() {
		RemapKeys := !RemapKeys
		if RemapKeys
			ShowTransText("游戏模式")
		else
			ShowTransText()
	}
return

#If RemapKeys
	j::Left
	l::Right
	i::Up
	k::Down
#If

IsDoubleClick() {
	static doubleClickTime := DllCall("GetDoubleClickTime")
	KeyWait, % LTrim(A_ThisHotkey, "~")
	return (A_ThisHotKey = A_PriorHotKey) && (A_TimeSincePriorHotkey <= doubleClickTime)
}

; ShowTransText("Hello")
; ShowTransText("Hello", 10, 10, {bgColor:"0x1482DE", textColor:"White"})
ShowTransText(Text := "", X := 0, Y := 0, objOptions := "") {
	if (Text = "") {
		Gui, @STT_:Destroy
		return
	}

	o := {bgColor:"Black", textColor:"0x00ff00", transN:200, fontSize:12}
	for k, v in objOptions {
		o[k] := v
	}
	
	Gui, @STT_:Destroy
	Gui, @STT_:+AlwaysOnTop -Caption -SysMenu +ToolWindow +E0x20 +HWNDhGUI
	Gui, @STT_:Font, % "s" o.fontSize
	Gui, @STT_:Color, % o.bgColor
	Gui, @STT_:Add, Text, % "c" o.textColor, %Text%
	Gui, @STT_:Show, x%X% y%Y% NA
	WinSet, Transparent, % o.transN, ahk_id %hGUI%
}
之前长按 Alt 也会被 IsDoubleClick 认为是双击,现已修复。

g1879

Re: 如何实现多层键盘切换?

Post by g1879 » 17 Nov 2019, 19:41

tmplinshi wrote:
16 Nov 2019, 11:28
楼主应该是想要显示一个背景色半透明的窗口,我多提供一个代码吧。

Code: Select all

~Alt::
	if IsDoubleClick() {
		RemapKeys := !RemapKeys
		if RemapKeys
			ShowTransText("游戏模式")
		else
			ShowTransText()
	}
return

#If RemapKeys
	j::Left
	l::Right
	i::Up
	k::Down
#If

IsDoubleClick() {
	static doubleClickTime := DllCall("GetDoubleClickTime")
	KeyWait, % LTrim(A_ThisHotkey, "~")
	return (A_ThisHotKey = A_PriorHotKey) && (A_TimeSincePriorHotkey <= doubleClickTime)
}

; ShowTransText("Hello")
; ShowTransText("Hello", 10, 10, {bgColor:"0x1482DE", textColor:"White"})
ShowTransText(Text := "", X := 0, Y := 0, objOptions := "") {
	if (Text = "") {
		Gui, @STT_:Destroy
		return
	}

	o := {bgColor:"Black", textColor:"0x00ff00", transN:200, fontSize:12}
	for k, v in objOptions {
		o[k] := v
	}
	
	Gui, @STT_:Destroy
	Gui, @STT_:+AlwaysOnTop -Caption -SysMenu +ToolWindow +E0x20 +HWNDhGUI
	Gui, @STT_:Font, % "s" o.fontSize
	Gui, @STT_:Color, % o.bgColor
	Gui, @STT_:Add, Text, % "c" o.textColor, %Text%
	Gui, @STT_:Show, x%X% y%Y% NA
	WinSet, Transparent, % o.transN, ahk_id %hGUI%
}
之前长按 Alt 也会被 IsDoubleClick 认为是双击,现已修复。
谢谢你

Guest

Re: 如何实现多层键盘切换?

Post by Guest » 17 Nov 2019, 19:43

fwejifjjwk2 wrote:
15 Nov 2019, 23:31
@Guest

Code: Select all

keyboard_state = 0

intInterval := 300
~LAlt::
    if (A_PriorHotkey <> "~LAlt" or A_TimeSincePriorHotkey > intInterval)
    {
        KeyWait, LAlt
        return
    }
    Else {
        if (keyboard_state = 1 ){
            EnvAdd, keyboard_state ,-1
            Gui,Destroy
        }
        Else {
             EnvAdd, keyboard_state ,1
            ;SoundBeep, 200, 300
            showtext(1)
        }
    }
return

#if (keyboard_state = 1)
    
	j::Left
	l::Right
	i::Up
	k::Down
#if ; End #if
    

showtext(str)
{
    x := 10
    y := 10
    Gui,Destroy
    Gui,+AlwaysOnTop +Disabled -Caption -SysMenu +Owner +LastFound
    WinGet,hwnd,ID
    Gui, font, s26 ECF3F7 w600, Verdana
    Gui, Color, ECF3F7
    WinSet, TransColor, ECF3F7
    Gui,Add,Text,BackgroundTrans,%str%
    Gui, Show, NoActivate Y%y% X%x% NA, Title of Window
}

非常感谢

qwfpgj

Re: 如何实现多层键盘切换?

Post by qwfpgj » 17 Feb 2020, 05:40

@tmplinshi
我在1.1.32的版本下使用出现了问题,您的长按修复版本并没有修复问题,在我运行脚本之后,第一次长按alt还是会被视为双击,而映射后,再次长按并不能将上下左右映射回来,只能通过双击使上下左右变回jkil,我的解决方案是在您的代码起始处加入keywait命令,之后运行效果良好。现修改如下,供参考:

Code: Select all

~Alt::
        keyWait, Alt
	if IsDoubleClick() {
		RemapKeys := !RemapKeys
	}
return

#If RemapKeys
	j::Left
	l::Right
	i::Up
	k::Down
#If

IsDoubleClick() {
	static doubleClickTime := DllCall("GetDoubleClickTime")
	KeyWait, % LTrim(A_ThisHotkey, "~")
	return (A_ThisHotKey = A_PriorHotKey) && (A_TimeSincePriorHotkey <= doubleClickTime)
}


Post Reply

Return to “请求帮助”