I need something that repeats the keyboard keys "up, left, down and right" and repeats endlessly until the insert key is pressed to pause it. I'm not sure how i should approach this. Could someone help point me in the right direction?
I am not on a windows computer at the moment, so this code is untested
This is for ahk_L not ahk_basic.
You will need to create a hotkey to start this loop.
You should also make sure this runs only on the window you are indending, as well as a way to quickly exit the script, as the script may run away from you, causing you to restart the computer.
; While the physical insert key is up, send the keystrokes
While(!GetKeystate("Insert","D")) {
Send {Up}{Left}{Right}{Down}
}
If this is for a game, (and I suspect it might be) you might need to use a difrerent send mode. See the Autohotkey FAQ for info on that particualr topic.
Related
My first question here.
As I'm writing code normaly, sometimes I need to copy. And like every 50-100 Ctrl+C copys, the mouse pointer goes to another part of the code and it doesn't copy what was selected (I mainly use eclipse IDE, but I believe this happened in other editors). It's like I was pressing Ctrl+LMB.
This kinda happens randomly and I can't seem to replicate it. I believe I'm misclicking a key but I never do realize what I just did.
This can really piss me off and I can't find anything online related.
Is it just me? Does anyone have an ideia what could be happening?
I would like to run a Power Automate flow by pressing a keyboard shortcut or alternatively calling it up from CMD or Powershell script.
The flow would simply start execution once the keyboard shortcut is pressed or a Powershell script is run.
As it is now; I need to start Power Automate and then click on play in order to start a specific flow. I am trying to avoid all that.
The ultimate goal is to, once the system is up (Windows 10) and I'm logged it, I press the shortcut key and go do something else and by the time I get back the flow is done. The flow itself works flawlessly. Please note that I am not looking for a solution which would involve smartphones and flow buttons on said phones, purely a Windows , PC, only solution or a way to a solution.
Here is a picture to clarify what Lukas was describing as a workaround.
Create a loop and make sure that the index variable for the loop is 0 so that it will never stop looping. Then make sure to put a 'wait for shortcut key' inside of the loop with you desired shortcut. Below that action and still inside of the loop, put all of your actions.
Run the script and the script will enter the loop at the 'wait for shortcut action. When the shortcut is pressed it will run all of the actions and then loop back to the 'wait for shortcut action again. As long as the script is running in the background the shortcut can trigger it.
Surprisingly, I do not think there is a way to do this. The best solution would probably be to use AutoIT to create a small automation to start your PAD flow.
As long as you're somewhat familiar with programming and even if you're not familiar with AutoIT, it shouldn't take you but a couple hours to write a script that is activatable via hotkey that opens PAD and starts the flow you want.
The AutoIT help file that you get when you install should be all the guidance you need.
(Depending on what your flow actually does, you might be better off just writing your whole automation in AutoIT)
You actually don't need to put everything in a loop, the loop is just from the end of the script to the top label. You just need a label at the top (if you want to be able to press the shortcut more than once), a wait for shortcut key event, and at the end a "go to the label" you created (in the image below it's 'start').
Then you can save the flow and start it. Nothing will happen until you press your shortcut key. Then the flow will execute, and return to the top, waiting for you to press your shortcut again.
You can even have errors go to the start label, instead of ending the script, so that the flow "stays alive".
Just put label on top of your code and then "Wait for shortcut key" and at the end use "go to" function, that will loop the code. This works for me
To give you an intro, I am not a programmer but a biologist who is learning a bit of programming.
Now I use OneNote a lot and continuously switch between typing and touch-based inking.
Now OneNote UWP does not have a shortcut for selecting a pen.
But I found out that by pressing Alt+d and then down and then continuously pressing right six times and then pressing enter, one can switch to pen via keyboard.
Now I want to automate the above process and link it to Numpad 1.
So I tried AutoHotkey and tried to learn making a script of the above command but still no success.
This is what I tried (3-4 different ways):
Numpad1::
!d
Down
Right
Right
Right
Right
Right
Right
Right
Enter
I know this script is wrong but I can't find the correct way to do it.
You're off to a good start! In order to send the keystrokes, you'll need to use one of the variations of the Send command. In addition, we can also make it so that it only work when OneNote is the active window using the #If directive. (It makes hotkeys context-sensitive.)
I don't have OneNote on my machine, but please verify that the title contains "OneNote" for the following script to work.
SetTitleMatchMode , 2
#If WinActive("OneNote")
Numpad1::Send , !d{down}{right 6}{enter}
#If
Edit: I installed OneNote to try it out. It appears to run too quickly. I added a key delay of 75ms and changed Send to SendEvent, which obeys the key delay. This worked fine for me:
SetTitleMatchMode , 2
SetKeyDelay , 75
#If WinActive("OneNote")
Numpad1::SendEvent , !d{down}{right 6}{enter}
#If
I have just purchased the Steelseries apex gaming keyboard and rival mouse. Unfortunately, each of these products has different software for macros and keyboard lighting, both of which are mediocre at most.
Instead of having 2 processes running in the background and having to use 2 crappy programs to write my macros, I have decided to use AutoHotkey for my macros, some of which I plan on making quite complex. The mouse was no problem in AutoHotkeys, with the two side buttons using XButton1 and XButton2, however no matter what I do, I can't detect my keyboard macro keys (M1 to M12 and MX1 to MX10).
Using a keyboard hook doesn't detect any keys, and looking online I can't find how to reference these keys either. I'm not even sure windows sees them, as when I try to input them into the shortcut key field in a normal shortcut they do nothing. So my questions are:
What is the name for the macro keys on my keyboard in AutoHotkey?
Is there any way to work around this problem without having to use the Steelseries Engine?
If I can't access them normally, is there a way to reassign them without external software?
(Optional) Is there any way to adjust the lighting on the keyboard and mouse without the Steelseries software as well?
Btw I'm using Windows 8 and here are the links to the mouse and keyboard. Thank you in advance.
You can get the name for special keys that are not listed in AutoHotkey documentation by following steps here.
Some notes and explanations:
You can use that script for step 1:
#InstallKeybdHook
Sleep, 99999999999999999999
When you run it, check if keyboard hook is active by:
press here:
then here:
and if active, you should see something like here:
In the step 6 the hex value column is here:
If that is not working for you, try Alternate solutions in the link that I provided before.
My script is supposed to press a button somewhere in my window, upper left. It is not working as it should be. I tried this:
ControlClick ClassNN ThunderRT6UserControlDC29, ahk_class ThunderRT6FormDC
Yet it doesn't work.
I tried the manual option:
Controlclick x160 y60, ....
But that doesn't work as well.
Eventually I resorted to a mere:
Click 160, 60 and that does work.
I was wondering why it is behaving like that? Also, is there a way for merely the button to get pressed without the mouse actually going all the way over there. I looks stupid and it is slow.
The main reason for me asking this question is because it is closely related to another question I posed:
How to obtain textual contents from a window
The common denominator is that anything with classNN and ahk_class seems to be problematic.
Try running script as a administrator (if you're on Windows 7 or Vista)
I finally found my own solution after skimming the documentation more thoroughly:
https://autohotkey.com/docs/commands/ControlClick.htm#Reliability
You can specify NA as the sixth parameter to wait for the mouse button to lift.
I found that when firing Control, Check, ,Button1 prior to ControlClick the click didn't work, but adding the NA to the end somehow magically fixed it. I suppose a click was being simulated and had not yet lifted.
First, make sure you have the capitalization correct. controlclick is case and space sensitive - everything in the name has to be correct.
Second, for your mouse-moving issue - first save the position of your mouse, then controlclick, and then put your mouse back where you found it. The mouse will only be out of place for the duration of either the click or the timeout. 160ms is not noticeable.
You might also try using ahk to activate the window, bringing it the front, and then seeing if you can tab through the controls to the one you want, and then push it by sending keys like space or return to the window in the forefront (which you have activated). This avoids using controlclick altogether. Some windows can be tricky.
Controlclick x160 y60,A,,Left,1, NA
Manual option like that should work,at least in my case it worked.
Left = your mouse button pressed
1 = number of clicks
A = Active Window
Also options to retrieve contents from the games or retrieve variables from other autohotkey parts for ControlClicks or SendMessage/PostMessage seem to not work yet.