Sign in to follow this  
Followers 0
c.haslam

HotKey persists when switching to another application

9 posts in this topic

#1 ·  Posted (edited)

In an Autoit script, I set Ctrl_S as a hotkey: HotKeySet("^s","SaveData"). Ctrl_S should only execute SaveData() when Form1 is active; a menuitem on this form is "Save Ctrsl_S".

I then open another application. When I press Ctrl_S, SaveData() is executed. This is not what I want!

How do I restrict execution of SaveData() to when the script is running and this form is active?

...chris

Edited by c.haslam

...chris

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

just use GUISetAccelerators :)

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

just use GUISetAccelerators :)

Hi,

You can use _IsPressed with options

#Include <misc.au3>

While 1
If _Ispressed("11") and _IsPressed("53") and WinActive("yourapp","") Then
;if ctrl+s and the window of your app is active
_SaveData()
Endif
Wend
Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

You can also simply do :

HotKeySet("{LCTRL}{S}","_SaveData")

Func _SaveData()
If winActive("your app window","") Then
;your function
EndIf
EndFunc

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Many thanks to all.

...chris

BTW Where do I find the codes for HotKey() and _IsPressed()? I have found a table of ASCII character codes in the Help, but not for keystrokes.


...chris

Share this post


Link to post
Share on other sites

Many thanks to all.

...chris

BTW Where do I find the codes for HotKey() and _IsPressed()? I have found a table of ASCII character codes in the Help, but not for keystrokes.

search in the help file for ''Send Key List''

Share this post


Link to post
Share on other sites

Robjong,

Thanks. I have the GUISetAccelerators() approach working.

...chris


...chris

Share this post


Link to post
Share on other sites

search in the help file for ''Send Key List''

The Send Key List gives the constituent parts of the argument of SendKeys (and GUISetAccelerators) but _isPressed takes a numeric argument.

...chris


...chris

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0