Comments (11)
Ok, I delete AHK_PATH
variable and now everything is works without extra definition to path.
from ahk.
This is interesting. Thanks for providing the report and permission details @XCanG
I haven't been able to reproduce this on my local system running as admin or otherwise in either cmd or powershell. Our CI tests in AppVeyor also run as an administrator.
One possible key difference is that I usually install ahk and place the autohotkey executable in a virtualenv (e.g. in venv/Scripts
) and let ahk
discover the executable this way.
I'm still searching for answers on why this permission issue may happen. One possible reason would be a bug in how executable_path
is being formed. For example, if somehow executable_path
is a directory rather than the actual .exe, it would produce this Permission Denied error. There may be a bug there. If you are using the AHK_PATH
env variable or specifying the path by keyword, be sure to use absolute path directly to the executable.
Could you tell me what the output is of
print(ahk.executable_path)
Also, try the following steps to setup an environment and see if you have different results....
mkdir test
cd test
py -3.7 -m venv venv
venv\Scripts\activate
python -m pip install ahk
copy D:\Prog\AutoHotkey\AutoHotkey.exe venv\Scripts
Then try running your script.
Also it would be good to know what version of Windows you are running and if you are in a domain environment or not. And, if possible, provide full code you have for instantiating ahk
.
If none of the above works for you. I'm wondering if adding shell=True
to the subprocess.Popen
call would help your situation.
from ahk.
>>> print(ahk.executable_path)
D:\Prog\AutoHotkey\
Running script from virtulenv have same error.
Full code is test code from example:
from ahk import AHK
ahk = AHK()
ahk.mouse_position = (200, 200)
last line throw error...
Windows 10 x64 version 10.0.17134
from ahk.
Ok, this is interesting.
So, somehow, the lib is incorrectly detecting the executable_path
.
D:\Prog\AutoHotkey\
should be D:\Prog\AutoHotkey\AutoHotkey.exe
!
If you do the following, it should alleviate the problem.
ahk = AHK(executable_path='D:\\Prog\\AutoHotkey\\AutoHotkey.exe')
Let me know if that fixes things.
Meantime, I'll investigate why this is happening. Basically, if you set AHK_PATH
, that is used... otherwise shutil.which
is used to find the executable, which should be giving the full path, not just the directory.
from ahk.
Oh, yes, defining path to .exe
helps, now script run without error.
from ahk.
In global environment variable Path
have this path ...;D:\Prog\AutoHotkey\;
... (not in user environment)
And I also have global AHK_PATH
which is fully equal to:
D:\Prog\AutoHotkey\
from ahk.
Ah, so AHK_PATH
should be the full path including the filename AutoHotkey.exe
. Alternatively, if you simply make the AHK_PATH
variable undefined, it should find the executable automagically.
Can you try removing that global AHK_PATH
var and see if it works automatically?
If that works, I'll be sure to update the docs to make this more clear.
from ahk.
Glad that works. So the behavior is as expected, but this tells me that maybe the docs or interface needs some work.
Perhaps a better name for the AHK_PATH
variable would be less confusing, since in PATH
you just specify the directory... Alternatively, maybe we shouldn't use the variable at all.
from ahk.
I guess if you want to use AHK_PATH
you make little check if it end to .exe
otherwise you add os.path.join(AHK_PATH, "AutoHotkey.exe")
.
from ahk.
That's definitely a possible solution.
Technically, the executable can be named anything and the extension is not necessary or could even be something else entirely. For example, if someone really wanted the executable to be named C:\corp_auto_tool.bin
and have that in AHK_PATH
and expect it to work.
I think what I'd lean towards in a code-based approach to this would be to add a check and raise an error if this variable is mis-configured.
maybe something like
if os.path.isdir(executable_path):
raise ValueError('AHK_PATH must be a file, not a directory')
Anyhow, I'll have to give this some more thought and will probably include a change in the next release.
Meanwhile, I'll update the docs, too.
If you'd like to make a PR against this, I'd happily review.
from ahk.
Marking this one as resolved and using #32 to track progress on action items for changes.
Feel free to reopen or pick up in 32 if you have more questions on this.
Thanks again for the report!
from ahk.
Related Issues (20)
- mouse_drag method errors with "Invalid index.. Specifically: 8" HOT 2
- key_wait method does not work as expected
- ahk to arrange windows up and down HOT 4
- Why is window.id a string? HOT 5
- Hide tray icon at runtime HOT 3
- Tray menu and tooltips don't appear unless AHK executor is "stimulated" HOT 5
- Window.from_pid() not working HOT 10
- Invalid Index when calling `key_state()` in v2 HOT 2
- After locating a window, unable to send key presses to window. HOT 3
- win_move does not work in AutoHotkey v2 unless width and height are specified
- Ability to use HWND to target controls in Control methods
- detect_hidden_windows does not work as expected in some cases when using AutoHotkey v2
- msg_box crashes with AHK v2 HOT 2
- Tooltip text and title mixed up HOT 2
- ahk.key_state("XButton2") does not return true in V2 HOT 14
- Traceback when adding hotkeys after hotkeys are started
- Modify traytip for Hotkey process
- Add numlock and scroll lock set states HOT 3
- ahk.key_down not working as expected HOT 3
- key_state fails when retrieving joystack name
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 ahk.