phil294 / AHK_X11

AutoHotkey for Linux (X11-based systems)
GNU General Public License v2.0
815 stars 15 forks source link

Command 'while' not found #71

Open NSC9 opened 7 months ago

NSC9 commented 7 months ago

I am converting this autohotkey script, which works on Windows, to Ubuntu Linux.

I removed If errorlevelsince it did not work as expected either.

Currently, I have written this, which returns 'command while not found':

f10::LButton
*LButton::
    while GetKeyState("LButton", "P")
        Sendinput {Click}
        Sleep, 66
        KeyWait, LButton
return

I checked the docs for crystal-language and there exists a while command.

Tried cleaning up the code with doc syntax:

f10::LButton
*LButton::
while GetKeyState,LButton, P == True
    Sendinput {Click}
    Sleep, 66
    KeyWait, LButton
return

edit: not sure if relevant, but I just found https://phil294.github.io/AHK_X11/#Loop.htm

phil294 commented 7 months ago

Hello,

Ahkx11 was itself built with Crystal, but you use this thing to code in AutoHotkey. Please forget Crystal. May I ask why you thought the Crystal docs mattered for your use case? So I can improve the Readme.

Your cleaned up code block looks better, but indeed while doesn't exist. Also Sendinput doesn't. You can figure this out by looking in the "alphabetical list of commands" from the docs, where there is no mention of either of those (everything is a command in AHK). You need to use Loop instead, the one you have rightfully already linked. Also AHK code is not indentation-based, so {s are also necessary.

But even with all of this, your code doesn't work because of a bug where it's not possible to send a key while it is also pressed down (#26). You currently need to use different keys for sending/clicking and the check for KeyWait.

yeah all of this is pretty confusing, not really sure what to do about it except make the Readme even longer... it's simply not entirely outsider-friendly

NSC9 commented 7 months ago

Hello,

Ahkx11 was itself built with Crystal, but you use this thing to code in AutoHotkey. Please forget Crystal. May I ask why you thought the Crystal docs mattered for your use case? So I can improve the Readme.

Your cleaned up code block looks better, but indeed while doesn't exist. Also Sendinput doesn't. You can figure this out by looking in the "alphabetical list of commands" from the docs, where there is no mention of either of those (everything is a command in AHK). You need to use Loop instead, the one you have rightfully already linked. Also AHK code is not indentation-based, so {s are also necessary.

But even with all of this, your code doesn't work because of a bug where it's not possible to send a key while it is also pressed down (#26). You currently need to use different keys for sending/clicking and the check for KeyWait.

yeah all of this is pretty confusing, not really sure what to do about it except make the Readme even longer... it's simply not entirely outsider-friendly

The Readme mentioned it was built with crystal. I originally assumed it would run just as AutoHotKey code, until I ment the "whilecommand not found" message. I checked crystal docs to troubleshoot to see if crystal offered that functionality. Sendinput is mentioned twice in the full doc so I was not entirely sure if it was included or not.

In one perspective, my script might not be exactly remapping the LButton to the Lbutton, but rather remapping LButton to a while loop which contains actions like the LButton. I noticed on the Readme there is a section on mouse remap do's & don'ts, but all those examples were 1:1 direct remaps. I simply need send, {LButton down} within the while loop. Could a work-around be to remap LButton to continuously send "left mouse clicks at the current relative x-y coordinate position until LButton is in GetKeyState U?" I don't want to drag any items either, so artificial clicks must function like send, {LButton down}.

phil294 commented 3 months ago

oh, indeed, there's a bug in the documentation, will fix

No, the problem is that it simply isn't possible to "send" a mouse button / click, while you're holding down the key physically, no matter what you code around it! This limitation also exists with xdotool, for example: Try sleep 1; xdotool click 1 in a console, run it, but then in the first second keep left mouse button pressed down. xdotool won't be able to do a mouse click.

NSC9 commented 2 months ago

I do not understand what you mean by “it simply isn't possible to "send" a mouse button / click, while you're holding down the key physically, no matter what you code around it!”

If we are talking about functionality of an operating system, do you agree that, in theory, any function on one operating system may be replicated on another operating system? I have already built this functionality and it works as an Autohotkey script that does what you say is impossible on AHK v1.1 on Windows, but I wish to port the functionality to GNU/Linux.

Do you know exactly what the difference is between GNU/Linux and Windows that prevents GNU/Linux from mirroring this functionality? Is it something with the desktop environments (Gnome/Cinnamon/etc) or display servers (Wayland/X11)?

Linked is the original AutoHotKey script (v1.1) I wish to convert from Windows to GNU/Linux (I verified it even works on Windows Vista). https://github.com/NSC9/Sample_of_Work/blob/Main/AHKs/RS4_Mouse_Improvement_Macro

My system info: Trisquel OS on Dasharo firmware

I have tried several Linux scripting alternatives like Autokey, Pyautogui, xdotools, and pynput. All have a range of problems. Autokey does not allow the left mouse button to itself be a hotkey. Pynput and other tools struggle at making while loops stop immediately when the left mouse button enters the UP keystate (see https://github.com/moses-palmer/pynput/issues/588).

I have tried using Wine, but it seems clunky. Functionality and performance of the AHK matters. Executing the hotkey with the left mouse button is a requirement. I went as far as to try using virtualbox with windows 7 running my AHK. Surprisingly, VM'ing the solution almost worked if not for the bad FPS due to virtualbox not supporting GPU integration!

My options are 1) go back to native Windows OS, 2) find a virtual machine solution that one could game on, 3) create a custom fork of AutoKey that supports binding hotkeys to mouse buttons, 4) shop around for computer mouse that is GNU/Linux-friendly that ships with a built-in macro functionality can do what I wish.

I have looked at converted AHK for GNU/Linux programs; either ones like IronAHK have been abandoned or I find myself laughing when I read limitations like https://github.com/phil294/AHK_X11?tab=readme-ov-file#caveats

I made a post on Reddit explaining my situation and there was one solution proposed 27 days ago that I will also experiment with. The solution proposed looks quite ugly though and would prefer something simple like an AHK keybind. https://www.reddit.com/r/learnpython/comments/1bk5pqw/pynput_script_so_close_to_working_please_help_btc/

ChatGPT generated this which I may experiment as a potential solution as well: “Yes, there are several ways to achieve continuous clicking while the left mouse button is held down on GNU/Linux: 1. Using xautoclick: • xautoclick is a utility designed for automatic mouse clicking. You can configure it to click continuously while holding down a specific mouse button. • To install it, you can use your package manager. For example, on Debian-based systems: sudo apt-get install xautoclick”

On Mon, Jul 1, 2024 at 17:17 Philip Waritschlager @.***> wrote:

oh, indeed, there's a bug in the documentation, will fix

No, the problem is that it simply isn't possible to "send" a mouse button / click, while you're holding down the key physically, no matter what you code around it! This limitation also exists with xdotool, for example: Try sleep 1; xdotool click 1 in a console, run it, but then in the first second keep left mouse button pressed down. xdotool won't be able to do a mouse click.

— Reply to this email directly, view it on GitHub https://github.com/phil294/AHK_X11/issues/71#issuecomment-2201173800, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVV2LWYOQVNBQ4JRPSJYKATZKHIRPAVCNFSM6AAAAABDW2FFAGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBRGE3TGOBQGA . You are receiving this because you authored the thread.Message ID: @.***>