Processing Ajax...

Close Dialog


Close Dialog

Close Dialog

A recent AVG and Avast antivirus update is preventing DisplayFusion 9.9 from launching on some systems.
If you're running into this issue, please update to the latest DisplayFusion 10.0 Beta.

Loop Until Key Pressed (BFS.Input.IsKeyDown)

This function shows how to loop forever inside a function and listen for a keypress to break out of the loop. The keycode numbers are generated by the popup inside the code editor.
Minimum Version
Created By
Jon Tackabury (BFS)
Date Created
Oct 18, 2014
Date Last Modified
Oct 18, 2014

Scripted Function (Macro) Code

using System;
using System.Drawing;

// The 'windowHandle' parameter will contain the window handle for the:
//   - Active window when run by hotkey
//   - Window Location target when run by a Window Location rule
//   - TitleBar Button owner when run by a TitleBar Button
//   - Jump List owner when run from a Taskbar Jump List
//   - Currently focused window if none of these match
public static class DisplayFusionFunction
	public static void Run(IntPtr windowHandle)
		// loop forever
		while (true)
			// if you press Alt, Ctrl and G together this will exit the function
			if (BFS.Input.IsKeyDown("18;17;71"))
			// sleep for a bit so we don't run-up the CPU