Trigger an event on Key press in Windows

1

I need to trigger an event, say open music player with a particular music file, when I press a Key (other than the dedicated play/pause button).

How can I do that with taskscheduler (Schtasks.exe) ?

I am using Windows 8.1

MAKZ

Posted 2014-07-19T17:08:41.907

Reputation: 1 427

AFAIK no, but you could make a task, and then make a shortcut to that task, and set a keyboard shortcut for that shortcut. More info here. Or use AutoHotKey

– ᔕᖺᘎᕊ – 2014-07-19T17:11:50.887

Answers

4

AFAIK, there is no way to do this, but there is a workaround:

  1. Create the Task in Task Scheduler. Make the name short, non-spaced (to make it easy)
  2. Check the 'run with highest privileges box'
  3. Choose your action
  4. Test it (to make sure it works as expected)
  5. Go to Desktop, right click > New > Shortcut
  6. For the location, use schtasks /run /tn “TASKNAMEINQUOTES”, changing TASKNAMEINQUOTES with the task name (in step 1) (in quotes).
  7. Name the shortcut anything you want > finish
  8. Right click the shortcut, and make a keyboard shortcut in the 'Shortcut' tab, in the 'Shortcut key' field.

(From here, but without screenshots)


Alternatively use AutoHotKey.

Your script will look something like:

#z::Run "C:\Users\USERNAME\Music\iTunes\Example.mp3" (or if you've made a bat file, #z::Run "C:\Users\USERNAME\Documents\Example.bat")

#z:: means on the shortcut Windows+Z

ᔕᖺᘎᕊ

Posted 2014-07-19T17:08:41.907

Reputation: 5 559

Say I write a bat file with <<start "" "music.mp3">> and map the file to <<Action>> of task scheduler. Now I need to run the task when I press a key on keyboard. So I need the Trigger to be a key-stroke. How to do I make a particular key strok as a trigger? – MAKZ – 2014-07-19T17:26:50.630

@MAKZ The last step says how to do this. – ᔕᖺᘎᕊ – 2014-07-19T17:27:26.850