Core Function HotKeySet

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> HotKeySet( <keydef>, <function> ) </pre> === Description === Create a custom hotkey to run custom code or execute a function ==== keydef ==== The key(s) to use as the h...")
 
(Example)
Line 46: Line 46:
 
GUILink($B1, @lClick, 'msgbox("Hello World!");');
 
GUILink($B1, @lClick, 'msgbox("Hello World!");');
  
HotKeySet("+!d", "myfunction();");  ;Shift-Alt-d
+
HotKeySet("+!d", "myfunction();");  //Shift-Alt-d
  
 
Until ( GUIState( $GUI ) == @sClosed ) DoEvents();
 
Until ( GUIState( $GUI ) == @sClosed ) DoEvents();
Line 60: Line 60:
 
Function captureEsc()
 
Function captureEsc()
 
{
 
{
     ; ... can do stuff here
+
     // ... can do stuff here
 
     HotKeySet("{Esc}");
 
     HotKeySet("{Esc}");
 
     SendKeys("{Esc}");
 
     SendKeys("{Esc}");

Revision as of 05:44, 26 November 2011

HotKeySet( <keydef>, <function> )

Contents

Description

Create a custom hotkey to run custom code or execute a function

keydef

The key(s) to use as the hotkey. Same format as SendKeys().

function

Optional; The name of the code to execute or the function to call when the key is pressed. Leave blank to unset a previous hotkey.

Return Value

Success: Returns 1.

Failure: Returns 0.

Remarks

Up to 64 simultaneous hotkeys per script may be registered.

If two AutoIt scripts set the same HotKeys, you should avoid running those scripts simultaneously. (The second script cannot capture the hotkey unless the first script terminates or unregisters the key prior to the second script setting the hotkey.)

Hotkeys can run at the same time as other hotkeys and even other functions.

The following hotkeys cannot be set:

Ctrl+Alt+Delete; It is reserved by Windows F12; It is also reserved by Windows, according to its API. NumPad's Enter Key; Instead, use {Enter} which captures both Enter keys on the keyboard. Win+B,D,E,F,L,M,R,U; and Win+Shift+M These are built-in Windows shortcuts. Note: Win+B and Win+L might only be reserved on Windows XP and above. Alt, Ctrl, Shift, Win These are the modifier keys themselves! Other Any global hotkeys a user has defined using third-party software, any combos of two or more "base keys" such as '{F1}{F2}', and any keys of the form '{LALT}' or '{ALTDOWN}'.

Example

$GUI = GUICreate("mooooo", 200, 200);
GUISetState($GUI, @Show);
$B1 = GUICreateButton($GUI, "mybutton", "PRESS ME!!!", 8, 8);
GUILink($B1, @lClick, 'msgbox("Hello World!");');
 
HotKeySet("+!d", "myfunction();");  //Shift-Alt-d
 
Until ( GUIState( $GUI ) == @sClosed ) DoEvents();
 
Function myfunction()
{
	println("Hello from the HOTKEY\n");
}
HotKeySet("{Esc}", "captureEsc();");
Function captureEsc()
{
    // ... can do stuff here
    HotKeySet("{Esc}");
    SendKeys("{Esc}");
    HotKeySet("{Esc}", "captureEsc();");
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox