I need a macro that starts when I press the F8 key and up
Moderators: Dorian (MJT support), JRL
-
- Newbie
- Posts: 15
- Joined: Sat Dec 12, 2009 11:20 pm
I need a macro that starts when I press the F8 key and up
OnEvent>Key_Down,VK119,0,MainMacro
SRT>MainMacro
send>a
END>MainMacro
Label>IdleLoop
Wait>0.01
Goto>IdleLoop
That macro is good but work only if i press F8
I need a macro that starts when I press the F8 key and button and up key
(example the macro work when i press control F8)
Anyone can help me? please
SRT>MainMacro
send>a
END>MainMacro
Label>IdleLoop
Wait>0.01
Goto>IdleLoop
That macro is good but work only if i press F8
I need a macro that starts when I press the F8 key and button and up key
(example the macro work when i press control F8)
Anyone can help me? please
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
So you want:
OnEvent>Key_Down,VK119,2,MainMacro
Note the bold parameter. The help topic for OnEvent says for this Key_Down parameter:
OnEvent>Key_Down,VK119,2,MainMacro
Note the bold parameter. The help topic for OnEvent says for this Key_Down parameter:
0: No modifier key
1: SHIFT key must also be pressed
2: CONTROL key must also be pressed
3: ALT key must also be pressed
4: SHIFT + ALT keys must be pressed
5: CONTROL + ALT keys must be pressed
6 SHIFT + CONTROL keys must be pressed
7: CONTROL + ALT + SHIFT keys must also be pressed
8: Windows key must also be pressed
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Newbie
- Posts: 15
- Joined: Sat Dec 12, 2009 11:20 pm
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Up is not a modifier key so there is no way to do that.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
I like to think there's always a way. Sometimes its just not a provided way like a built in modifier key. By using a variable flag we can make any key a modifier key. While the value of the variable "F8KeyWasPressed" is zero, pressing up will only do whatever "Up" does. But wjen the F8 key is held down the value of "F8KeyWasPressed" is set to one. While it is one the subroutine tied to the Up key will perform whatever task you want the combination of F8+Up to perform.
Code: Select all
//F8=VK119
OnEvent>key_down,VK119,0,SetFlag
//Up=VK38
OnEvent>key_down,VK38,0,DoStuff
Let>F8KeyWasPressed=0
SRT>SetFlag
Let>F8KeyWasPressed=1
END>SetFlag
SRT>DoStuff
If>F8KeyWasPressed>0
MDL>The key combination of F8 and Up were pressed
EndIf
END>DoStuff
Label>Loop
Wait>0.01
If>F8KeyWasPressed>0
Add>F8KeyWasPressed,1
If>F8KeyWasPressed>10
Let>F8KeyWasPressed=0
EndIf
EndIf
Goto>Loop
Ditto - nicely done JRL... good concept.JRL wrote:I like to think there's always a way.
On testing this, I find it also "fires" if you tap one then the other in fast succession... i.e. F8 and the Up Arrow key are not actually being pressed down simultaneously... but it still fires. Also, maybe 10% of the time, I pressed them both down more or less simultaneously and it did not fire at all... but on the next try it fired. This may be good enough for the poster's purposes though, good concept.
Since neither F8 nor the Up arror key can be a modifier... the only other technique I can think of might be... to keep the two OnEvents, one fires if F8 is down and one fires if Up Arrow key is down... and in the subroutine for each, don't check a flag, check directly (using a Win API call?) to see if the other key is also presently down and if so, perform the required function.
Just a thought, take care.
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
In the "Loop", there is a line that says:On testing this, I find it also "fires" if you tap one then the other in fast succession... i.e. F8 and the Up Arrow key are not actually being pressed down simultaneously... but it still fires.
If>F8KeyWasPressed>10
Change the 10 to a 2 and that issue will go away. What is happening is that there is a lag between when when the F8 key is released and the variable "F8KeyWasPressed" is set back to zero. During that lag, pressing the Up key will still pop up the modal message. Changing the ten to a two will reduce the lag to a more acceptable level.
With any real modifier key, pressing the two keys exactly simultaneously or pressing the main key prior to pressing the modifier key does not execute what ever the key combination is supposed to execute. That is also why I think that even if you used a Win API call as you described at the end of your post, you'd still need some sort of flag system to make one key a modifier of the other. Otherwise it wouldn't matter whether you pressed the up key first or the F8 key first.Also, maybe 10% of the time, I pressed them both down more or less simultaneously and it did not fire at all...
I think the primary caveate to this is that usually a modifier actually modifies the activity performed by the main key being pressed. In this case the activity for the key is not actually altered. If there is an activity in the focused application that will be affected by the Up key, it will still be affected by the up key. This could be rectified by adding code similar to that found in THIS POST. By intercepting the keystroke(s) a script could be written that absolutely controls the actions of the keys.
Yup, that definitely improves it.JRL wrote:Changing the ten to a two will reduce the lag to a more acceptable level.
Also, maybe 10% of the time, I pressed them both down more or less simultaneously and it did not fire at all...
Yes and that's the point, with the change I suggested, it would not matter which key actually was pressed before the other... if either one is pressed, an OnEvent fires which will then check if "the other" key is also down and if it is... it has caught the fact that they are both down at the same time. I don't know at this point if there is a Win API call that can check that but if so, the concept seems valid.JRL wrote:With any real modifier key, pressing the two keys exactly simultaneously or pressing the main key prior to pressing the modifier key does not execute what ever the key combination is supposed to execute. That is also why I think that even if you used a Win API call as you described at the end of your post, you'd still need some sort of flag system to make one key a modifier of the other. Otherwise it wouldn't matter whether you pressed the up key first or the F8 key first.
We don't know if the poster wanted either the F8 keypress or the Up keypress or both to be passed through to whatever application has focus at the time... or intercepted by this macro. If intercepted then yes, your technique at that post might be perfect.JRL wrote:I think the primary caveate to this is that usually a modifier actually modifies the activity performed by the main key being pressed. In this case the activity for the key is not actually altered. If there is an activity in the focused application that will be affected by the Up key, it will still be affected by the up key. This could be rectified by adding code similar to that found in THIS POST. By intercepting the keystroke(s) a script could be written that absolutely controls the actions of the keys.
Another caveat of the code you have provided... is that it has been written "as if" F8 was a modifier and Up was the key it was modifying... and by that I mean... I can press and hold down F8 and then very shortly after press and hold down Up and it always works... but if I switch the order around... i.e. hit the Up key first and then the F8 after, it absolutely never fires.
So, depending on the habit of the user and which key of those two they naturally hit first, if its F8, use your code as-is but if they normally hit the Up key first, they'd have to re-write it to switch around Up and F8 in your code.
Take care
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Ok, so we could use the GetKeyState function. The following will work when pressing F8+UP together:
Note two key down event handlers, one for UP and one for F8 the one for UP checks the keystate of the F8 key and the F8 handler chekcs the keystate of the UP key. The message is displayed if pressed. So this means we can detect both being pressed together. Insert a call to your subroutine in place of the MessageModal.
Code: Select all
//UP=VK38
OnEvent>key_down,VK38,0,UpPressed
//F8=VK119
OnEvent>key_down,VK119,0,F8Pressed
Label>idle_loop
Wait>0.2
Goto>idle_loop
SRT>UpPressed
//Up was pressed, get VK_F8 keystate
Let>VK_F8=119
LibFunc>user32,GetKeyState,result,VK_F8
If>result<0
MessageModal>F8+UP was pressed
Endif
END>UpPressed
SRT>F8Pressed
//F8 was pressed, get VK_UP keystate
Let>VK_UP=38
LibFunc>user32,GetKeyState,result,VK_UP
If>result<0
MessageModal>F8+UP was pressed
Endif
END>F8Pressed
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Yes that's exactly it Marcus, thanks... and thanks JRL for the concept.
Take care all
Take care all
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -