I want to be able to send a keypress (such as left, right, etc) based on pixel color on the screen. For example, if this pixel equals this value, send this keypress. What is the best way to do this?
I might add that this would have to be scanning the screen constantly looking at the same spot until the moment it spots the desired pixel, then sending the key
In any language/script, how can I send keys via pixel/pic?
Moderators: Dorian (MJT support), JRL
Here's a demo program. See the comments and read help for functions you're not familiar with. This will detect black and white on the pixel located in the center of your screen.
Code: Select all
//Setting OnEvent to detect the press of the Esc key
//the press will trigger subroutine "Esc" which will set
//variable Stop_Flag to 1. When the Stop_Flag variable is detected as 1
//by the Stop_Flag if> statement, The script will jump to label EOF and end.
OnEvent>KEY_DOWN,VK27,0,Esc
Let>Stop_Flag=0
//Using this to get a point in the middle of the screen
//You can designate any point or points in the GetPixelColor> function.
//Next three lines for demo purposes only.
GetScreenRes>Scr_X,Scr_Y
Let>Scr_X=%Scr_X%/2
Let>Scr_Y=%Scr_Y%/2
//An endless loop that will continuously detect the color at the
//designated location using GetPixelColor. If> statements will jump
//to specific subroutines based on specific colors being detected.
Label>GetPixelColorLoop
GetPixelColor>Scr_X,Scr_Y,color
If>Stop_Flag=1,EOF
If>%color%=16777215,White
If>%color%=0,Black
//A short wait to keep the processor from overheating
Wait>0.001
Goto>GetPixelColorLoop
Label>EOF
SRT>White
//Modal message for demonstration purposes
MDL>Screen Position %Scr_X%,%Scr_Y% is white
//Press anykey
//wait some amount of time for the screen to change
//or it will continue pressing the designated key every
//thousandth of a second.
Wait>2
END>White
SRT>Black
MDL>Screen Position %Scr_X%,%Scr_Y% is black
//Press anykey
Wait>2
END>Black
SRT>Esc
Let>Stop_Flag=1
END>Esc