how to conditionally modify a programs hotkey behavior

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
drstuggi
Newbie
Posts: 9
Joined: Sun Feb 14, 2021 8:53 pm

how to conditionally modify a programs hotkey behavior

Post by drstuggi » Sat Aug 12, 2023 8:15 pm

Hi everyone!

I use a medical journal application on a daily basis. The F2 function key is used to affirm some, but unfortunately not all dialogue windows. For example in some cases I have to either manually clik "ok" button, or press an illogical key combination to dismiss the dialogue window.
Therefore I tried to make a script that uses F2 as a hotkey trigger, with some conditional behavior based on the active window name. This works ok as long as I don't need the F2 key to function as originally intended (for example the F2 key is used to duplicate a journal entry in the application).
I've tried to make a "passthrough", ie in cases where I just want a F2 press to send F2 to the application, but unsurprsingly this leads to an endless loop of script self-activation, since F2 is the hotkey for the script.
I then attempted to use the trigger function in macro scheduler, so that a specific window would start a script with this simple code (VK113 is the virtual key code for F2):

Code: Select all

//wait for F2 press
OnEvent>KEY_DOWN,VK113,,ClickOK

//send ctrl-o to dialogue window
SRT>ClickOK
  Press CTRL
  send>o
  Release CTRL
END>ClickOK
This doesn't work. I actually can't get OnEvent to work at all (tried different virtual keys, with and without using script triggers).
Perhaps OnEvent doesn't work when using a Remote Desktop connection, as I am at the moment.

I hope someone will enlighten me.
Forgive me for the long and perhaps confusing post

User avatar
Grovkillen
Automation Wizard
Posts: 1024
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: how to conditionally modify a programs hotkey behavior

Post by Grovkillen » Sun Aug 13, 2023 9:32 am

OnEvent>KEY_DOWN,VK113,0,ClickOK
Let>ME=%Script%

Running: 15.0.24
version history

drstuggi
Newbie
Posts: 9
Joined: Sun Feb 14, 2021 8:53 pm

Re: how to conditionally modify a programs hotkey behavior

Post by drstuggi » Sun Aug 13, 2023 1:03 pm

Thank you for the quick reply. Unfortunately still doesnt work. I can't even get a message to show up with this code:

Code: Select all

//wait for F2 press
OnEvent>KEY_DOWN,VK113,0,ClickOK

//send ctrl-o to dialogue window
SRT>ClickOK
  MessageModal>F2 pressed
  //Press CTRL
  //send>o
  //Release CTRL
END>ClickOK

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1354
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: how to conditionally modify a programs hotkey behavior

Post by Dorian (MJT support) » Sun Aug 13, 2023 3:10 pm

Code: Select all

//wait for F2 press
OnEvent>KEY_DOWN,VK113,0,ClickOK

label>start
wait>0.1
goto>start

//send ctrl-o to dialogue window
SRT>ClickOK
  MessageModal>F2 pressed
  //Press CTRL
  //send>o
  //Release CTRL
END>ClickOK
Yes, we have a Custom Scripting Service. Message me or go here

drstuggi
Newbie
Posts: 9
Joined: Sun Feb 14, 2021 8:53 pm

Re: how to conditionally modify a programs hotkey behavior

Post by drstuggi » Sun Aug 13, 2023 5:12 pm

Thank. Will try that. Could you please explain the background for using this seemingly endless loop this would create?

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1354
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: how to conditionally modify a programs hotkey behavior

Post by Dorian (MJT support) » Sun Aug 13, 2023 6:14 pm

Without the loop the script isn't running. It will start and immediately reach the end. Step through it line by line and you'll see.
Yes, we have a Custom Scripting Service. Message me or go here

drstuggi
Newbie
Posts: 9
Joined: Sun Feb 14, 2021 8:53 pm

Re: how to conditionally modify a programs hotkey behavior

Post by drstuggi » Sun Aug 13, 2023 6:44 pm

Ok. But shouldn’t the label start be on the first line?

User avatar
Grovkillen
Automation Wizard
Posts: 1024
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: how to conditionally modify a programs hotkey behavior

Post by Grovkillen » Sun Aug 13, 2023 6:52 pm

No the label is put wherever you need it to be but you need to make sure the event is set before the loop starts. Or else it will never be initiated.
Let>ME=%Script%

Running: 15.0.24
version history

drstuggi
Newbie
Posts: 9
Joined: Sun Feb 14, 2021 8:53 pm

Re: how to conditionally modify a programs hotkey behavior

Post by drstuggi » Sun Aug 13, 2023 7:03 pm

I’m a noob. I’m sure it will make sense some day 🙂. Thanks!

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts