RadioGroup used to emulate a "Slider Bar"

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3517
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

RadioGroup used to emulate a "Slider Bar"

Post by JRL » Wed Oct 11, 2006 5:25 am

I had an idea for moving the mouse cursor around the screen by pressing the arrow keys. Then I thought it would be nice to have a slider bar to control the cursor speed. Not having one available it occured to me to use the RadioGroup feature. The following is the result. I don't really have any practical use for this but somone might find the slider bar concept useful.

Later,
Dick

Edit: Fixed mistake in comment for F12 virtual key code.

Code: Select all

//Waiting for left arrow (VK37)
OnEvent>KEY_DOWN,VK37,0,srt1
//Waiting for up arrow (VK38)
OnEvent>KEY_DOWN,VK38,0,srt2
//Waiting for right arrow (VK39)
OnEvent>KEY_DOWN,VK39,0,srt3
//Waiting for down arrow (VK40)
OnEvent>KEY_DOWN,VK40,0,srt4
//Waiting for Alt+F12
//F12 (VK123)plus    2=Alt
OnEvent>KEY_DOWN,VK123,2,srt5

//This repeat loop constructs the text for the RadioGroup.
//The text is composed of a string of periods
//delimited by %CRLF%.
Let>k=0
Let>RadText=
Repeat>k
  Add>k,1
  Concat>RadText,.%CRLF%
Until>k,40

//The edit box in the dialog is there to have an item to contain the cursor
//otherwise pressing the arrow keys will move the radioGroup selection.  The
//SpeedSelect variable will be made unequal to the itemindex value
//when a new selection is made in the radiogroup.  When this occurs
//a comparison test will fail and tab will be pressed moving the dialog
//cursor into the edit box. 
Dialog>Dialog1
   Caption=Arrow Cursor Speed
   Width=138
   Height=411
   Top=CENTER
   Left=CENTER
   Close=0
   Label=Faster,48,16
   Label=Slower,48,288
   Edit=msEdit1,48,313,33,msEdit1
   RadioGroup=msRadioGroup1,,48,32,33,249,%RadText%.,0
   Button=Quit,30,312,75,25,2
   Button=Help,30,344,75,25,3
EndDialog>Dialog1

//Construct a variable for the Help Text
//This is primarily for readability and ease of editing
Let>HelpText=Pick a point on the "slider bar" and set the speed%CRLF%
Concat>HelpText,for the mouse cursor to be moved by the arrow keys%CRLF%%CRLF%
Concat>HelpText,Pressing Ctrl+F12 will set the left mouse button down%CRLF%
Concat>HelpText,for dragging with the mouse.%CRLF%%CRLF%
Concat>HelpText,Pressing Ctrl+F12 a second time will release the mouse button.

Dialog>Dialog3
   Caption=Arrow Key cursor Help
   Width=326
   Height=231
   Top=CENTER
   Left=CENTER
   Close=0
   Label=%HelpText%,16,16
   Button=Ok,112,160,75,25,3
EndDialog>Dialog3

Show>Dialog1
Let>MouseDown=0
Let>SpeedSelect=0

Label>start
GDA>Dialog1,r1
If>r1=2,quit
If>r1=3
  Show>Dialog3,r3
  CloseDialog>Dialog3
  RDA>Dialog1
EndIf
If>%SpeedSelect%<>%dialog1.msRadioGroup1.itemindex%
  Let>SpeedSelect=%dialog1.msRadioGroup1.itemindex%
  Set>Arrow Cursor Speed
  Press Tab
EndIf

//WaitTime is a variable for Wait in the arrow key subroutines.
//It is based on the RadioGroup Item Index value which I added to
//2 then multiplied times .001.  The multiplier is an arbitrary number
//as is the choice to add 2.
Let>WaitTime={(0.001*(2+%dialog1.msRadioGroup1.itemindex%))}
//advance is a variable for the number of pixels to be moved each key
//cycle as the arrow key is held down.  This was simply a way to make
//the cursor move faster.  The "Round" function is needed to prevent fractional
//results which are rejected by the Mouse Move function.  Adding 1 to the
//item index is necessary to prevent division by zero.
Let>advance={1+(Round(10/(1+%dialog1.msRadioGroup1.itemindex%)))}
Wait>0.01
Goto>start

Label>quit

SRT>srt1
GCP>X,Y
sub>X,%advance%
Mou>%X%,%Y%
Wait>%WaitTime%
END>srt1

SRT>srt2
GCP>X,Y
sub>Y,%advance%
Mou>%X%,%Y%
Wait>%WaitTime%
END>srt2

SRT>srt3
GCP>X,Y
add>X,%advance%
Mou>%X%,%Y%
Wait>%WaitTime%
END>srt3

SRT>srt4
GCP>X,Y
add>Y,%advance%
Mou>%X%,%Y%
Wait>%WaitTime%
END>srt4

SRT>srt5
If>%MouseDown%=0
  Let>MouseDown=1
  LDown
  Wait>0.1
Else
  Let>MouseDown=0
  LUp
  Wait>0.1
EndIf
END>srt5
Last edited by JRL on Wed Oct 18, 2006 9:57 pm, edited 1 time in total.

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

Post by Marcus Tettmar » Wed Oct 11, 2006 7:32 am

Cool! :-)
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Wed Oct 11, 2006 1:15 pm

Wow :shock:

hvdberg
Junior Coder
Posts: 39
Joined: Wed Jul 12, 2006 1:50 pm
Location: Netherlands

Post by hvdberg » Wed Oct 11, 2006 2:08 pm

Agreed, cool. Playing with it a bit, I found out that when you want to adjust the cursor speed, holding the CTRL-key while in the 'slider' control, you can adjust the speed without needing to TAB around like you need to when you press up/down on its own (see comment just above Dialog1)

Best,
Henk

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