Press random key?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Mlrs327
Newbie
Posts: 7
Joined: Wed Oct 31, 2018 10:39 pm

Press random key?

Post by Mlrs327 » Sun Nov 04, 2018 5:38 pm

Anyway to script a random keystroke of a specific set of keys? Like "O", "P", "S", "OO", "PS"...let the script pick any combination of those keys and send it

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Press random key?

Post by Marcus Tettmar » Sun Nov 04, 2018 11:27 pm

Code: Select all

//list of possible keystrokes
Let>keystrokes=O,P,S,OO,PS

//separate to an array
Separate>keystrokes,comma,arrKeys

//get a random number within the range 0 - length of array -1
Random>arrKeys_count,randKeyNumber

//add one to random number (our array starts at 1)
Let>randKeyNumber=randKeyNumber+1

//get the key combo from the array using that index
Let>theKey=arrKeys_%randKeyNumber%

//send it
Send>theKey
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Mlrs327
Newbie
Posts: 7
Joined: Wed Oct 31, 2018 10:39 pm

Re: Press random key?

Post by Mlrs327 » Thu Nov 08, 2018 3:02 am

Awesome! Thanks you

Mlrs327
Newbie
Posts: 7
Joined: Wed Oct 31, 2018 10:39 pm

Re: Press random key?

Post by Mlrs327 » Fri Nov 09, 2018 6:37 pm

Hmmmm...its sending keys so fast the program is not catching it. Its not an issue with sk_delay...its the key itself, like the program needs human speed keypress duration and this is doing StarTrek press duration

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Press random key?

Post by Marcus Tettmar » Tue Nov 13, 2018 12:27 am

Split the press into a key down, a wait and a key up. You can do that with KeybdEvent.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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