Yes, you can simulate F12 being pressed.
Here's the snippet for simulating a F1 press, it will
$win32_keydb_event = Win32API.new 'user32', 'keybd_event', %w(l l l l), ''
$win32_keydb_event.call(0x70,0,0,0) # F1 down
$win32_keydb_event.call(0x70,0,2,0) # F1 up
The code the F12 button is
0x7B.
However since this is the F12 button it naturally would be so simple.
You must press F12 down for some time and this is where it becomes fun.
If you just press F12 down like this:
$win32_keydb_event = Win32API.new 'user32', 'keybd_event', %w(l l l l), ''
$win32_keydb_event.call(0x70,0,0,0) # F12 down
You'll keep restarting. Ever tried holding F12 down? There you have it.
Now... How will you call the F12 up function if the game keeps restarting?
One way is this:
Thread.new {
$win32_keydb_event = Win32API.new 'user32', 'keybd_event', %w(l l l l), ''
$win32_keydb_event.call(0x7B,0,0,0) # F12 down
sleep(0.1)
$win32_keydb_event.call(0x7B,0,2,0) # F12 up
}
I press the F12, let the thread sleep in 0.1 seconds and release F12.
In practice it takes much longer. Certainly something to do with it restarting.
You can decrease the sleep, but if it is too little nothing will happen. (F12 being pressed down and released too quickly issue)
Naturally this being a Thread how long a sleep is required varies from run to run.
You can try to increase the thread's priority like this:
aThread = Thread.new {
$win32_keydb_event = Win32API.new 'user32', 'keybd_event', %w(l l l l), ''
$win32_keydb_event.call(0x7B,0,0,0) # F12 down
sleep(0.1)
$win32_keydb_event.call(0x7B,0,2,0) # F12 up
}
aThread.priority = 1
I don't know if it has any effect at all and it might effect other programs you have running.