Page 1 of 1

Automatic Switch Toggling

Posted: Tue Jan 24, 2012 1:29 am
by medelec35
I have developed a way to automatically toggle any switch in Flowcode simulator, which can toggle an i/p very rapidly without you toggling the switches yourself!
This is just like like a Clock generator which I believe is long overdue .
Clock generator or Automatic Switch toggling works by using a third parties software called AutoHotkey.
AutoHotkey can be programmed to control any key with any key presses.

First download AutoHotkey from:
http://www.autohotkey.com/download/
I downloaded Installer for AutoHotkey Basic (1.95 MB)

Please note this software is freeware and appears to be genuine with a support forum. I have used it on a couple of PC's with no issues whatsoever. I have even scanned with Microsoft Security Essentials with nothing found. But as with all software downloaded from the internet, it's at your own risk.
After downloaded and installed you don't need to save sample scrip when prompted since you will be using the attached script (.ahk extension) I developed just for the Automatic Switch toggling.

Save Flowcode Toggle Keys.ahk to any folder on your PC.when saved you can double click file to run AutoHotkey software. When running there will be a green square Icon with a White H in the tray or your PC.
HotKeys1.png
(4.37 KiB) Downloaded 4894 times
Now load the flowchart that's also contained within the attached zip file.
I have set up the flowchart with key mapping which I have explained about here:
http://www.matrixmultimedia.com/mmforum ... 219#p21219

With the Key mapping set up, you press key 5 to toggle switch thats it's mapped to.
key mapping1.png
(62.46 KiB) Downloaded 4892 times
Every time that key 5 is pressed then since the switch is assigned to port B5 interrupt-on -change, number on LCD is incremented by one.
Now for the automation part.
I have set up AutoHotkeys so if click run on Flowcode then hold Ctrl and Alt and press number 5 on the top row of keyboard, then the number 5 will be rapidly repeated.
To stop 5 from being constantly activated then press Space bar.

Note: it is not advisable to click on any text input box after you have activated the repeating key or you will just see 555555555555555555555555 going across the input box or text editor. You will need to press space bar to stop repeat function first.
You can also stop the the script by right clicking on AutoHotkeys icon that's in the windows task bar.

Here is what the script looks like I have created for AutoHotkeys:

Code: Select all

;Auto Toggle Switches

;By Medelec35
 


^!$0::  ; Make the Ctrl Alt 0 key into a hotkey (the $ symbol facilitates the "P" mode of GetKeyState below).
 sleep 100
Loop  ; Since no number is specified with it, this is an infinite loop unless "break" or "return" is encountered 

inside.
{
    if GetKeyState("space", "P")  ; If this statement is true, the user has just pressed the space bar to stop.
        break  ; Break out of the loop.
    ; Otherwise (since the above didn't "break"), keep sending 0
    send 0  ; 
 sleep 60 ; time in ms between activation key 1
}
sleep 100
return


^!$1::  
 sleep 100
Loop  
{
    if GetKeyState("space", "P")  
        break  
    send 1  
 sleep 60 
}
sleep 100
return


^!$2::  
 sleep 100
Loop  
{
    if GetKeyState("space", "P")  
        break  
    send 2  
sleep 60 
}
sleep 100
return

^!$3::  
 sleep 100
Loop  
{
    if GetKeyState("space", "P")  
        break  
    send 3  
sleep 60 
}
sleep 100
return

^!$4::  
 sleep 100
Loop  
{
    if GetKeyState("space", "P")  
        break  
    send 4  
sleep 60 
}
sleep 100
return

^!$5::  
 sleep 200
Loop  
{
    if GetKeyState("space", "P")  
        break  
    send 5  
sleep 60 
}
sleep 100
return

^!$6::  
 sleep 100
Loop  
{
    if GetKeyState("space", "P")  
        break  
    send 6  
sleep 60 
}
sleep 100
return

^!$7::  
 sleep 100
Loop  
{
    if GetKeyState("space", "P")  
        break  
    send 7  
sleep 60 
}
sleep 100
return

^!$8::  
 sleep 100
Loop  
{
    if GetKeyState("space", "P")  
        break  
    send 8  
sleep 60 
}
sleep 100
return

^!$9::  
 sleep 100
Loop  
{
    if GetKeyState("space", "P")  
        break  
    send 9  
sleep 60 
}
sleep 100
return
I have set the script to work with numbers 0 to 9 (in conjunction with Ctrl and Alt)

As a test I started the switch toggling and number on LCD went from 0 to 300 in 23 seconds.
Bearing in mind that count is increment only when key 5 is pressed and released.
The script can be altered to go even faster if required.

Have fun and don't forget you use the space bar to stop key 5 being repeat pressed.

Hope I have giving enough information as it took me a little while to work out the script, and its late for me.

Martin

Re: Automatic Switch Toggling

Posted: Wed Jan 25, 2012 3:41 pm
by echase
I have never understood Key mapping and not found the Help button enlightening on this point. But if I understand your description a keymap is linking a PC keyboard key to an action in Flowcode. If so what is the “Element” entry in your picture and why do both SWITCH(0) and SWITCH(1) have zero for Element?

Re: Automatic Switch Toggling

Posted: Wed Jan 25, 2012 4:19 pm
by medelec35
echase wrote:But if I understand your description a keymap is linking a PC keyboard key to an action in Flowcode.
I agree with that statement.
If I have got it correct, then the switch only has 1 element since it's either activated or not and only requires 1 Key to operate. You could think of an element as number of keys less 1( so with 1 key, element = 1-1 =0) mapped to it. So any component that contains a on/off action e.g switch keypad etc. will always have 0 for element.
A pot will have 2 elements ( 0 = counter clockwise & 1 = clockwise) since there are two keys mapped to it. One key for clockwise and another key for counter clockwise.
The number on the left is the keyboard number that's mapped to component.
So if you have 5 for switch(0) then pressing 5 will activate switch(0) just select element 0

Hope I have helped.

Martin