AutoHotkey Community

It is currently May 27th, 2012, 6:20 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: December 6th, 2010, 6:07 pm 
Offline

Joined: March 29th, 2010, 7:32 pm
Posts: 31
In many contexts, Ctrl + Backspace deletes the previous word. It works, for example, in Word, WordPad, the address line and text boxes in IE and Firefox.

But there many contexts it does not work, but should! So I am using AHK top extend Ctrl + Backspace functionality to other programs.

Is there an way to specify the scope of the script to a list of contexts? Or do I have to make a separate command for each window or class?

Code:
#IfWinActive ahk_class TfrmCmdDialog
; How to I expand above so other windows/classes are recognized?
;
$^Backspace::
ClipSaved := ClipboardAll   ; Store the current clipboard
Clipboard :=         ; Clear the clipboard
SendInput ^+{Left}^c      ; Select word to left, and copy to clipboard
ClipWait 0.05         ; Wait a little for clipboard to populate
If (StrLen(Clipboard) > 0)   ; Only delete if something is on the clipboard
   {
   SendInput {Delete}
   }
Clipboard := ClipSaved   ; Restore the original clipboard
ClipSaved =   ; Free the memory in case the clipboard was very large
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 6th, 2010, 6:15 pm 
Offline

Joined: May 1st, 2010, 6:01 pm
Posts: 1020
Location: England
you have have the same hotkey within two different windows using #ifwinactive

so you can do this sort of thing

Code:
#ifwinactive, window1
space::msgbox, hello
#ifwinactive, window2
space::msgbox, hello
#ifwinactive, window3
space::msgbox, hello
#ifwinactive, window4
space::msgbox, hello


Code:
#ifwinactive, window1
;your code
#ifwinactive, window2
;your code
#ifwinactive, window3
;your code
#ifwinactive, window4
;your code


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 6th, 2010, 6:22 pm 
Offline

Joined: March 29th, 2010, 7:32 pm
Posts: 31
This will help keep things tidy...

Code:
#IfWinActive ahk_class TfrmCmdDialog
#Include Ctrl_Backspace.ahk

#IfWinActive ahk_class XYZ
#Include Ctrl_Backspace.ahk

#IfWinActive ahk_class ABC
#Include Ctrl_Backspace.ahk

etc.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 6th, 2010, 7:04 pm 
Offline

Joined: March 29th, 2010, 7:32 pm
Posts: 31
... except it does not work. I have tried a number of variations, but to no avail. The hotkey is recognized only in the first of the two cases. (Same result when I flip the two around.)

Code:
#IfWinActive ahk_class Notepad
$^Backspace::
#include Delete_Word_Left.ahk
return

#IfWinActive ahk_class TfrmCmdDialog
$^Backspace::
#include Delete_Word_Left.ahk
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 6th, 2010, 9:20 pm 
Offline

Joined: May 1st, 2010, 6:01 pm
Posts: 1020
Location: England
i havnt tested but i would assume that it should look something like this.
try that

Code:
#IfWinActive ahk_class TfrmCmdDialog
; How to I expand above so other windows/classes are recognized?
;
$^Backspace::
ClipSaved := ClipboardAll   ; Store the current clipboard
Clipboard :=         ; Clear the clipboard
SendInput ^+{Left}^c      ; Select word to left, and copy to clipboard
ClipWait 0.05         ; Wait a little for clipboard to populate
If (StrLen(Clipboard) > 0)   ; Only delete if something is on the clipboard
   {
   SendInput {Delete}
   }
Clipboard := ClipSaved   ; Restore the original clipboard
ClipSaved =   ; Free the memory in case the clipboard was very large
return

#IfWinActive ahk_class window2
; How to I expand above so other windows/classes are recognized?
;
$^Backspace::
ClipSaved := ClipboardAll   ; Store the current clipboard
Clipboard :=         ; Clear the clipboard
SendInput ^+{Left}^c      ; Select word to left, and copy to clipboard
ClipWait 0.05         ; Wait a little for clipboard to populate
If (StrLen(Clipboard) > 0)   ; Only delete if something is on the clipboard
   {
   SendInput {Delete}
   }
Clipboard := ClipSaved   ; Restore the original clipboard
ClipSaved =   ; Free the memory in case the clipboard was very large
return

#IfWinActive ahk_class window3
; How to I expand above so other windows/classes are recognized?
;
$^Backspace::
ClipSaved := ClipboardAll   ; Store the current clipboard
Clipboard :=         ; Clear the clipboard
SendInput ^+{Left}^c      ; Select word to left, and copy to clipboard
ClipWait 0.05         ; Wait a little for clipboard to populate
If (StrLen(Clipboard) > 0)   ; Only delete if something is on the clipboard
   {
   SendInput {Delete}
   }
Clipboard := ClipSaved   ; Restore the original clipboard
ClipSaved =   ; Free the memory in case the clipboard was very large
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 6th, 2010, 9:35 pm 
Offline

Joined: March 29th, 2010, 7:32 pm
Posts: 31
It sure is a lot of repetitive code!

Any thoughts on a way to make updates to a single script without having to change every instance of the same command?

Or is this just one of those learn-to-accept-the-limitations issues?

By the way, if anyone is interested in the script itself, I found a much simpler way to code it that doesn't use the clipboard:

Code:
$^Backspace::
   SendInput ^+{Left}{BackSpace}      ; Select word to left, and delete it


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 6th, 2010, 10:07 pm 
Offline

Joined: May 1st, 2010, 6:01 pm
Posts: 1020
Location: England
heres a more-readable version (but not using #ifwinactive)

Code:
$^Backspace::
Winget, Title, A
if (Title = Notepad or Msn or Firefox or Notepad++)
SendInput ^+{Left}{BackSpace}      ; Select word to left, and delete it
Else
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 7th, 2010, 5:34 pm 
Offline

Joined: October 25th, 2009, 6:10 pm
Posts: 17
Try this:
Code:
If WinActive ("ahk_class Notepad") or WinActive (ahk_class rctrl_renwnd32) ;Outlook 2000 email, ctrl-backspace fails
; How to I expand above so other windows/classes are recognized?
;
$^Backspace::
send, +^{left}
sleep,100
send,{delete}
return


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], hd0202 and 55 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group