Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问怎么提取其中的鼠标模拟功能 #88

Closed
1205129045x opened this issue Jan 2, 2024 · 29 comments
Closed

请问怎么提取其中的鼠标模拟功能 #88

1205129045x opened this issue Jan 2, 2024 · 29 comments
Assignees

Comments

@1205129045x
Copy link

我想设置成按d键然后再按hjkl模拟鼠标上下左右的,该怎么看源码自己改?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Title: How to extract the mouse simulation function?

I want to set it to press the d key and then press hjkl to simulate the up, down, left and right movements of the mouse. How can I change it myself by looking at the source code?

@snomiao
Copy link
Member

snomiao commented Jan 3, 2024

如果是要把鼠標模擬拆出来的話,

  1. 主要是拆出来这2個文件
    .\Modules\AccModel\AccModel.ahk
    .\Modules\CLX-Mouse.ahk

  2. 把 CapsLockX_Config 換成你想要的值

  3. 刪掉 CapsLockX_AppendHelp

  4. 刪掉環境検査

if (!CapsLockX) {
    MsgBox, % "本模块只为 CapsLockX 工作"
    ExitApp
}
  1. 把 CapsLockXMode 替換成 HJKLMouseMode,然后把原有的熱鍵控制代碼換成你想要的様子,類似这样
; 按d键进入鼠标模式

#if

*d::
    global HJKLMouseMode := 1
    return
*d Up::
    global HJKLMouseMode := 0
    return

; 在 hjkl鼠標模式下,按下hjkl鍵,模擬鼠標移動
#if HJKLMouseMode

; 鼠标运动处理
*h:: 鼠标模拟.左按("h")
*l:: 鼠标模拟.右按("l")
*k:: 鼠标模拟.上按("k")
*j:: 鼠标模拟.下按("j")
  1. 可能存在的問題:
    1. d鍵作為触发鍵的話,可能影响輸入法。
    2. 以上示例未提供滚轮支持,也没提供鼠標点撃支持

@1205129045x 有思路了嗎

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


If you want to remove the mouse simulation,

  1. Mainly remove these two files
    .\Modules\AccModel\AccModel.ahk
    .\Modules\CLX-Mouse.ahk

  2. Replace CapsLockX_Config with the value you want

  3. Delete CapsLockX_AppendHelp

  4. Delete environment query

if (!CapsLockX) {
    MsgBox, % "This module only works with CapsLockX"
    ExitApp
}
  1. Replace CapsLockXMode with HJKLMouseMode, and then replace the original hotkey control code with the one you want, similar to this
; Press the d key to enter mouse mode

#if

*d::
    global HJKLMouseMode := 1
    return
*d Up::
    global HJKLMouseMode := 0
    return

; In hjkl mouse mode, press the hjkl key to simulate mouse movement
#if HJKLMouseMode

;Mouse motion processing
*h:: Mouse simulation. Left click ("h")
*l:: Mouse simulation. Right click ("l")
*k:: Mouse simulation. Press up ("k")
*j:: Mouse simulation. Press down ("j")
  1. Possible problems:
    1. If the d key is used as a trigger key, it may affect the input method.
    2. The above example does not provide scroll wheel support or mouse click support.

@1205129045x Do you have any ideas?

@snomiao snomiao self-assigned this Jan 3, 2024
@1205129045x
Copy link
Author

如果是要把鼠標模擬拆出来的話,

  1. 主要是拆出来这2個文件
    .\Modules\AccModel\AccModel.ahk
    .\Modules\CLX-Mouse.ahk
  2. 把 CapsLockX_Config 換成你想要的值
  3. 刪掉 CapsLockX_AppendHelp
  4. 刪掉環境検査
if (!CapsLockX) {
    MsgBox, % "本模块只为 CapsLockX 工作"
    ExitApp
}
  1. 把 CapsLockXMode 替換成 HJKLMouseMode,然后把原有的熱鍵控制代碼換成你想要的様子,類似这样
; 按d键进入鼠标模式

#if

*d::
    global HJKLMouseMode := 1
    return
*d Up::
    global HJKLMouseMode := 0
    return

; 在 hjkl鼠標模式下,按下hjkl鍵,模擬鼠標移動
#if HJKLMouseMode

; 鼠标运动处理
*h:: 鼠标模拟.左按("h")
*l:: 鼠标模拟.右按("l")
*k:: 鼠标模拟.上按("k")
*j:: 鼠标模拟.下按("j")
  1. 可能存在的問題:

    1. d鍵作為触发鍵的話,可能影响輸入法。
    2. 以上示例未提供滚轮支持,也没提供鼠標点撃支持

@1205129045x 有思路了嗎

太强了 你是作者吧 有思路了 周末开搞

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


If you want to remove the mouse simulation,

  1. Mainly remove these two files
    .\Modules\AccModel\AccModel.ahk
    .\Modules\CLX-Mouse.ahk
  2. Change CapsLockX_Config to the value you want
  3. Delete CapsLockX_AppendHelp
  4. Delete environment query

``ahk
if (!CapsLockX) {
MsgBox, % "This module only works for CapsLockX"
ExitApp
}


5. Replace CapsLockXMode with HJKLMouseMode, and then replace the original hotkey control code with the one you want, similar to this

``ahk
; Press d key to enter mouse mode

#if

*d::
global HJKLMouseMode := 1
return
*d Up::
global HJKLMouseMode := 0
return

; In hjkl mouse mode, press the hjkl key to simulate mouse movement
#if HJKLMouseMode

;Mouse motion processing
*h:: Mouse simulation. Left click ("h")
*l:: Mouse simulation. Right click ("l")
*k:: Mouse simulation. Press up ("k")
*j:: Mouse simulation. Press down ("j")
  1. Possible problems:

  2. If the d key is used as a trigger key, it may affect the input method.

  3. The above example does not provide scroll wheel support or mouse click support.

@1205129045x Do you have any ideas?

That's great. You are the author. You have an idea. I'll start working on it on the weekend.

Copy link

github-actions bot commented Feb 3, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Feb 3, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 8, 2024
@snomiao
Copy link
Member

snomiao commented Mar 28, 2024

如果是要把鼠標模擬拆出来的話,

  1. 主要是拆出来这2個文件
    .\Modules\AccModel\AccModel.ahk
    .\Modules\CLX-Mouse.ahk
  2. 把 CapsLockX_Config 換成你想要的值
  3. 刪掉 CapsLockX_AppendHelp
  4. 刪掉環境検査
if (!CapsLockX) {
    MsgBox, % "本模块只为 CapsLockX 工作"
    ExitApp
}
  1. 把 CapsLockXMode 替換成 HJKLMouseMode,然后把原有的熱鍵控制代碼換成你想要的様子,類似这样
; 按d键进入鼠标模式

#if

*d::
    global HJKLMouseMode := 1
    return
*d Up::
    global HJKLMouseMode := 0
    return

; 在 hjkl鼠標模式下,按下hjkl鍵,模擬鼠標移動
#if HJKLMouseMode

; 鼠标运动处理
*h:: 鼠标模拟.左按("h")
*l:: 鼠标模拟.右按("l")
*k:: 鼠标模拟.上按("k")
*j:: 鼠标模拟.下按("j")
  1. 可能存在的問題:

    1. d鍵作為触发鍵的話,可能影响輸入法。
    2. 以上示例未提供滚轮支持,也没提供鼠標点撃支持

@1205129045x 有思路了嗎

太强了 你是作者吧 有思路了 周末开搞

有進展吗 @1205129045x

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


If you want to remove the mouse simulation,

  1. Mainly remove these two files
    .\Modules\AccModel\AccModel.ahk
    .\Modules\CLX-Mouse.ahk
  2. Replace CapsLockX_Config with the value you want
  3. Delete CapsLockX_AppendHelp
  4. Delete environment query
if (!CapsLockX) {
MsgBox, % "This module only works for CapsLockX"
ExitApp
}
  1. Replace CapsLockXMode with HJKLMouseMode, and then replace the original hotkey control code with the one you want, similar to this
; Press d key to enter mouse mode

#if

*d::
global HJKLMouseMode := 1
return
*d Up::
global HJKLMouseMode := 0
return

; In hjkl mouse mode, press the hjkl key to simulate mouse movement
#if HJKLMouseMode

;Mouse motion processing
*h:: Mouse simulation. Left click ("h")
*l:: Mouse simulation. Right click ("l")
*k:: Mouse simulation. Press up ("k")
*j:: Mouse simulation. Press down ("j")
  1. Possible problems:

  2. If the d key is used as a trigger key, it may affect the input method.

  3. The above example does not provide scroll wheel support or mouse click support.

@1205129045x Do you have any ideas?

It’s so powerful. Are you the author? You have an idea. I’ll start working on it on the weekend.

Is there any progress @1205129045x

@snomiao
Copy link
Member

snomiao commented May 19, 2024

Some one done this, maybe its'you, how ever I archived into here

@snomiao snomiao closed this as completed May 19, 2024
@11215548
Copy link

11215548 commented Sep 2, 2024

上周末花了两天才搞出来,可以实现按d进入鼠标模式,组合hjkl负责移动,但是并不影响快速输入一个d和长按d。

#SingleInstance, Force
SetWorkingDir, %A_ScriptDir%
global MouseControlMode := false
global CapsLockXMode := true  ; 假设 CapsLockXMode 始终为真,您可以根据需要修改这个逻辑
global dKeyPressTime := 0
global dKeyHoldThreshold := 200  ; 长按阈值(毫秒)
global ReadyForMouseMode := false
$d::
    dKeyPressTime := A_TickCount
    MouseControlMode := true
    ReadyForMouseMode := true
    SetTimer, CheckHJKL, 10
    while (GetKeyState("d", "P"))
    {
        if (!ReadyForMouseMode && A_TickCount - dKeyPressTime > dKeyHoldThreshold)
        {
            if (!GetKeyState("h", "P") && !GetKeyState("j", "P") && !GetKeyState("k", "P") && !GetKeyState("l", "P"))
            {
                SendInput, {Blind}{d DownTemp}
                Sleep, 10
                SendInput, {Blind}{d Up}
            }
        }
        Sleep, 10
    }
    SetTimer, CheckHJKL, Off
    MouseControlMode := false
    ReadyForMouseMode := false
    if (A_TickCount - dKeyPressTime < dKeyHoldThreshold)
    {
        Send, d  ; 快速点击,输入 'd'
    }
return
CheckHJKL:
    if (ReadyForMouseMode && GetKeyState("d", "P") && (GetKeyState("h", "P") || GetKeyState("j", "P") || GetKeyState("k", "P") || GetKeyState("l", "P")))
    {
        MouseControlMode := false
        SetTimer, CheckHJKL, Off  ; 停止计时器,因为我们已经进入鼠标模式
    }
    if(A_TickCount - dKeyPressTime > 500 && MouseControlMode)
    {
        ReadyForMouseMode := false
        SetTimer, CheckHJKL, Off  ; 如果超过500ms没有进入鼠标模式,也停止计时器
    }
return
#if CapsLockXMode && ReadyForMouseMode
*h:: 鼠标模拟.左按("h")
*j:: 鼠标模拟.下按("j")
*k:: 鼠标模拟.上按("k")
*l:: 鼠标模拟.右按("l")
; 当释放 HJKL 键时停止移动
*h up:: 鼠标模拟.左弹("h")
*j up:: 鼠标模拟.下弹("j")
*k up:: 鼠标模拟.上弹("k")
*l up:: 鼠标模拟.右弹("l")

大佬你是怎么判断单按一下大写键是正常的大写。
接下来打算是按住d和s不放松,再按j或k实现上滚和下滚功能。
解放小拇指,不按大写键。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


It took two days to come up with it last weekend. You can press d to enter mouse mode. The combination hjkl is responsible for movement, but it does not affect the quick input of a d and the long press of d.

#SingleInstance, Force
SetWorkingDir, %A_ScriptDir%
global MouseControlMode := false
global CapsLockXMode := true ; Assuming CapsLockXMode is always true, you can modify this logic as needed
global dKeyPressTime := 0
global dKeyHoldThreshold := 200 ; Long press threshold (milliseconds)
global ReadyForMouseMode := false
$d::
    dKeyPressTime := A_TickCount
    MouseControlMode := true
    ReadyForMouseMode := true
    SetTimer, CheckHJKL, 10
    while (GetKeyState("d", "P"))
    {
        if (!ReadyForMouseMode && A_TickCount - dKeyPressTime > dKeyHoldThreshold)
        {
            if (!GetKeyState("h", "P") && !GetKeyState("j", "P") && !GetKeyState("k", "P") && !GetKeyState("l", "P"))
            {
                SendInput, {Blind}{d DownTemp}
                Sleep, 10
                SendInput, {Blind}{d Up}
            }
        }
        Sleep, 10
    }
    SetTimer, CheckHJKL, Off
    MouseControlMode := false
    ReadyForMouseMode := false
    if (A_TickCount - dKeyPressTime < dKeyHoldThreshold)
    {
        Send, d ; Quick click, enter 'd'
    }
return
CheckHJKL:
    if (ReadyForMouseMode && GetKeyState("d", "P") && (GetKeyState("h", "P") || GetKeyState("j", "P") || GetKeyState("k", "P") || GetKeyState("l", "P")))
    {
        MouseControlMode := false
        SetTimer, CheckHJKL, Off ; Stop the timer because we have entered mouse mode
    }
    if(A_TickCount - dKeyPressTime > 500 && MouseControlMode)
    {
        ReadyForMouseMode := false
        SetTimer, CheckHJKL, Off; If the mouse mode is not entered for more than 500ms, the timer will also be stopped.
    }
return
#if CapsLockXMode && ReadyForMouseMode
*h:: Mouse simulation. Left click ("h")
*j:: Mouse simulation. Press down ("j")
*k:: Mouse simulation. Press up ("k")
*l:: Mouse simulation. Right click ("l")
; Stop moving when HJKL key is released
*h up:: Mouse simulation. Left flick ("h")
*j up:: mouse simulation.down("j")
*k up:: Mouse simulation.Up("k")
*l up:: Mouse simulation. Right click ("l")

Sir, how do you determine that single-clicking the caps key is normal caps.
The next plan is to hold down d and s without relaxing, and then press j or k to implement the scroll up and down functions.
Free your little finger and don't press the caps key.

@snomiao
Copy link
Member

snomiao commented Sep 3, 2024

判断单按一下大写键是正常的大写。

  • 按下大写键之后,没跟其它键就弹起 = 正常大写
  • 按下大写键之后,跟了其它热键 = 走具体热键的功能

@11215548

@snomiao snomiao reopened this Sep 3, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Determine if single-clicking the caps key is normal caps.

  • After pressing the capital key, it pops up without pressing any other keys = normal capitalization
  • After pressing the capital key, follow other hotkeys = use the function of the specific hotkey

@11215548

@github-actions github-actions bot removed the Stale label Sep 4, 2024
@11215548
Copy link

11215548 commented Sep 8, 2024

我现在发现按d会有延迟,比如打这个字,我一般输入法都会按下d再按空格,按的比较快,空格就会先触发了,是不是程序有延迟

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I now find that there is a delay when pressing d. For example, when typing the word , I usually press d and then press space in the input method. If I press d faster, the space will be triggered first. Is there a delay in the program?

@snomiao
Copy link
Member

snomiao commented Sep 8, 2024

用来做触发键的肯定会有延迟的,用d的话打d会延迟,用空格的话打空格会延迟

我个人觉得空格延迟比较可以接受

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


There will definitely be a delay when used as a trigger key. If you use d to hit d, there will be a delay. If you use a space to hit a space, there will be a delay.

Personally, I think space delay is more acceptable.

@11215548
Copy link

11215548 commented Sep 9, 2024

用来做触发键的肯定会有延迟的,用d的话打d会延迟,用空格的话打空格会延迟

我个人觉得空格延迟比较可以接受

指的是用空格做触发键吗,有办法改代码让延迟不影响我快速打字吗

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


There will definitely be a delay when using the trigger key. If you use d to hit d, there will be a delay. If you use a space to hit a space, there will be a delay.

I personally think space delay is more acceptable

Does it mean using space as the trigger key? Is there a way to change the code so that the delay does not affect my fast typing?

@snomiao
Copy link
Member

snomiao commented Sep 10, 2024

具体来说,你在什么环节有延迟?

case1 使用clx, 按空格+热键
0ms 按下空格
100ms 按下热键 wasd
200ms 弹起空格

case2 使用clx,按空格,输出空格
0ms 按下空格
100ms 弹起空格(输出空格)

case3 不使用clx,输出空格
0ms 按下空格(输出空格)

如果你想打空格的话,case2相比case3多了100ms延迟
但为了让case1正常运行,空格不能直接在按下时立刻输出,目前CLX在这个情况使用了250ms延迟,打空格如果 不使用热键,会延迟250ms才输出空格,此时保持空格按下可连续输出空格。

相关代码见此
https://github.com/snomiao/capslockx/blob/71aadc2c23aee35d1b0745e5b5a0300309338bdc/Core/CapslockX-Core.ahk#L322C35-L340C10

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Specifically, where do you experience delays?

case1 uses clx, press space+hotkey
0ms press space
100ms hotkey pressed wasd
200ms pop up space

case2 uses clx, press space, and output spaces
0ms press space
100ms Pop up spaces (output spaces)

case3 does not use clx and outputs spaces
0ms press space (output space)

If you want to type spaces, case2 has an extra 100ms delay compared to case3.
However, in order for case1 to run normally, the space cannot be output immediately when pressed. Currently, CLX uses a 250ms delay in this case. If you do not use the hotkey to hit the space, it will delay the output of the space for 250ms. At this time, keep pressing the space to continue. Output spaces.

See the relevant code here
https://github.com/snomiao/capslockx/blob/71aadc2c23aee35d1b0745e5b5a0300309338bdc/Core/CapslockX-Core.ahk#L322C35-L340C10

@snomiao
Copy link
Member

snomiao commented Sep 10, 2024

关于打字,你可以使用不影响打字的引导键,比如右alt或capslock这些平时打字 不会用到的键做引导键,就不会导致打字延迟了

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Regarding typing, you can use guide keys that do not affect typing, such as right alt or capslock. Keys that are not used in normal typing are used as guide keys, which will not cause typing delays.

@11215548
Copy link

我现在的代码是。

$d::
    dKeyPressTime := A_TickCount
    while (GetKeyState("d", "P"))
    {
        //检测是否长按的
    }
    SetTimer, CheckHJKL, 10 //具体判断是否进入鼠标模式的代码。
    if (A_TickCount - dKeyPressTime < dKeyHoldThreshold)
    {
        Send, d  ; 快速点击,输入 'd'
    }
return

因为有这个while (GetKeyState("d", "P")),只有当d键弹开了,才会输入d,所以有延迟,但是又没法删掉,因为要检测是否会进入鼠标模式。
所以case情况是:
case1:单独按一下d
0ms 按下d
d键弹起,才会输入d

case2 长按d
会根据while重复输入d

case3 d和其他键连着按
都会出现其他键先被按出来,d才会被按出来,应该就是前面的while循环导致的。只有d弹起了,d才会输入。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


My current code is.

$d::
    dKeyPressTime := A_TickCount
    while (GetKeyState("d", "P"))
    {
        //Check whether long press
    }
    SetTimer, CheckHJKL, 10 //Code to specifically determine whether to enter mouse mode.
    if (A_TickCount - dKeyPressTime < dKeyHoldThreshold)
    {
        Send, d ; Quick click, enter 'd'
    }
return

Because of this while (GetKeyState("d", "P")), d will be entered only when the d key bounces, so there is a delay, but it cannot be deleted because it needs to detect whether the mouse will enter. model.
So the case is:
case1: press d alone
0ms Press d
Only when the d key pops up will d be entered.

case2 long press d
d will be entered repeatedly according to while

case3 d and other keys pressed continuously
It will appear that other keys are pressed first, and then d is pressed. This should be caused by the previous while loop. Only when d is played, d will be entered.

@snomiao
Copy link
Member

snomiao commented Sep 10, 2024

这样的話我建議你使用不影响打字的引导键,比如右alt或capslock这些平时打字 不会用到的键做引导键,就不会导致打字延迟了

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


In this case, I recommend that you use guide keys that do not affect typing, such as right alt or capslock, which are keys that are not used in normal typing. As guide keys, it will not cause typing delays.

@11215548
Copy link

这样的話我建議你使用不影响打字的引导键,比如右alt或capslock这些平时打字 不会用到的键做引导键,就不会导致打字延迟了

可以。老老实实用右alt或ctrl了。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


In this case, I suggest you use guide keys that do not affect typing, such as right alt or capslock, which are keys that are not used in normal typing. They will not cause typing delays.

Can. Just use alt or ctrl right.

@snomiao snomiao closed this as completed Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants