Jump to content
Macro Express Forums

If Keypress Then...


leoman
 Share

Recommended Posts

Would it be possible to use ME to achieve the following:

 

I have already set a specific macro to launch when a window opens. Now, can this macro be responsive to a keypress? E.g., if the user presses "1" something happens. If he does not, then something else happens.

 

I hope that made sense...

Link to comment
Share on other sites

I did try a few work arounds using the Wait for Text command, but it was late last night and I didn't come up with anything productive. I will try again today. The problem is that the Wait for Text command is good if you're looking for a specific keypress, but what if the key isn't pressed? How do you program in an alternative route for the macro to take.

 

Example:

1. Launch program.

2. I user presses key a, set up preferences for user one. If user presses key b, then set up preferences for user two. If no key is pressed, set up default preferences.

3. ...and so on.

 

I would like to avoid showing dialogue boxes or menus, etc. The idea is to use the keyboard as much as possible without cluttering the work space with additional graphical user interfaces.

 

I hope my goal is a little bit clearer now.

Link to comment
Share on other sites

Leo,

Can you be a tad more specific with one or two full examples? I'm a bit confused that you want a macro to run with a keypress and not have a menu? Will the end user know what each keypress represents? If so, set up the macro using if keypress. If they don't press it, nothing happens. Otherwise, you may have to either wait indefinetly or use a timer?

Robert

Link to comment
Share on other sites

An example macro using keypress in pseudo-code. The purpose of the macro is to help me annotate a music file. So when I hear a drum, I wrte "drum" in the text file; when I hear a guitar, I write "guitar" in the text file.

 

1) Start macro

2) Macro opens music editing programm

3) Macro opens text file

4) I hear a drum sound so I press key 1 and the macro writes "drum" to the text file

5) I hear a guitar and I press key 2 so the macro writes "guitar" to the text file

6) I press Esc and the macro saves the file and ends.

 

So, that's how I would like to be able to use keypresses. Since everything happens in real-time (while the song is playing), I don't want to have to hunt for the correct option in menu; keyboard commands are just so much faster.

 

Is this clearer now?

Link to comment
Share on other sites

Leo,

Try this

<IFOTH:01:2:C:\write.txt><DOFILE:08:NN:c:\write.txt>><ENDIF><WAITKEY2:000000:000000:27><TVAR2:01:01:drum><TMVAR2:20:01:00:000:000:c:\write.txtT><WAITKEY2:000000:000000:28><TVAR2:02:01:guitar><TMVAR2:20:02:00:000:000:c:\write.txtT><WAITKEY2:000000:000000:29><TVAR2:03:01:banjo><TMVAR2:20:03:00:000:000:c:\write.txtT>

 

 

Robert

Link to comment
Share on other sites

That's great, Robert. Thanks! I didn't know that the "wait for keypress" command could work like that.

 

I'm going to fiddle with the code a bit more now because it is adding only one entry for each instrument. E.g, if I press the key 1 three times, there is only one entry for drum in the text file.

 

Thanks again.

Link to comment
Share on other sites

Leo,

I just tried something with Repeat and without repeat and I'm not sure you will be able to achieve what you want unless you're prepared to go in order. Each wait except for the first is dependent on the previous it appears and if you put time on the delay, you'll get a timeout message. Maybe some of the more experienced members can jump in and lend some advice. Good Luck my friend!

Robert

Link to comment
Share on other sites

Try this... I think this might work for you. Rather than keypresses... uses a mulitple choice box in a repeat loop...

 

// Repeat Until "End of Music" Choice is selected
Repeat Until %T1% <> %T1%
 Multiple Choice Menu: Instruments
 Switch (T1)
   Case: A
     Variable Modify String: Append "Guitar, " to %T2%
   End Case
   Case: B
     Variable Modify String: Append "Drums, " to %T2%
   End Case
   Case: C
     Variable Modify String: Append "Saxophone, " to %T2%
   End Case
   Case: D
     Break
   End Case
 End Switch
Repeat End
// Launch/Activate specifc text program here

// Type out %T2% (list of instruments) to text file.
Text Type: %T2%
Macro Stop

 

 

<REM2:Repeat Until "End of Music" Choice is selected><REP3:08:000002:000001:0001:1:01:T1><MENU2:2:T:01:CenterCenter:InstrumentsGuitar
Drums
Saxophone
End of Music><SWITCH:T1><CASE:A><TMVAR2:07:02:00:000:000:Guitar, ><ENDCASE><CASE:B><TMVAR2:07:02:00:000:000:Drums, ><ENDCASE><CASE:C><TMVAR2:07:02:00:000:000:Saxophone, ><ENDCASE><CASE:D><BREAK><ENDCASE><ENDSWITCH><ENDREP><REM2:Launch/Activate specifc text program here><REM2:><REM2:Type out %T2% (list of instruments) to text file.><TEXTTYPE:%T2%><MSTOP>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...