The following script works to open Firefox's location/"awesome" bar from anywhere using control-l, except when using Acrobat/Adobe reader. This is because control-l in Acrobat goes full screen. It works, but it's ugly and uses nested #ifWinNotActive.
#IfWinNotActive, ahk_class MozillaWindowClass
#IfWinNotActive, ahk_class ahk_class AcrobatSDIWindow
^l::
WinActivate, ahk_class MozillaWindowClass
Send, ^l
return
#IfWinNotActive
#IfWinNotActive
The below code replacement doesn't work. Autohotkey doesn't complain with errors, but ignores the !WinActive conditionals and furthermore appears to become caught in an infinite loop. Any ideas why? (I tried the return statement both before and after the closing bracket.)
^l::
if (!WinActive(ahk_class,MozillaWindowClass)) and (!WinActive(ahk_class,AcrobatSDIWindow)) {
WinActivate, ahk_class MozillaWindowClass
Send, ^l
}
return
With the WinActive function you need quotes around ahk_class MozillaWindowClass
and you don't need the comma. The infinite loop could be resolved by adding a hook $.
$^l::
if (!WinActive("ahk_class MozillaWindowClass"))
and (!WinActive("ahk_class AcrobatSDIWindow"))
{
WinActivate, ahk_class MozillaWindowClass
Send, ^l
} else
Send, ^l
Return
However, writing it this way is only necessary if you are using AutoHotkey basic, which is out of date.
Unless you have a legitimate reason for not upgrading to AutoHotkey_L (which is unlikely)
you can accomplish what you were trying in the first example with the #If directive.
#If !WinActive("ahk_class CalcFrame") && !WinActive("ahk_class Notepad")
^l::
Run, notepad
Winwait, ahk_class Notepad
Send, test
Return
f1::traytip,, test
#If
In this example Ctrl+L and F1 will only work as coded if
calculator and/or notepad are not currently active,
otherwise they act as they normally would.
For anyone not familiar with AutoHotkey shorthand, ! means not.
Related
Sample script:
#NoEnv
#Warn
#SingleInstance Force
#IfWinActive Foo ahk_exe foo.exe
!A::Send Foo
SetTitleMatchMode Regex
#IfWinActive Bar$ ahk_exe bar.exe
!A::Send Bar
When running it, the interpreter throws:
I want to apply SetTitleMatchMode Regex only to bar.exe, is it achievable without putting it on top of the script?
Quote from SetTitleMatchMode Remarks:
Every newly launched thread (such as a hotkey, custom menu item, or timed subroutine) starts fresh with the default setting for this command. That default may be changed by using this command in the auto-execute section (top part of the script).
And quote from The Top of the Script (the Auto-execute Section):
After the script has been loaded, it begins executing at the top line, continuing until a Return, Exit, hotkey/hotstring label, or the physical end of the script is encountered (whichever comes first). This top portion of the script is referred to as the auto-execute section.
I'm trying to move a program's window to 0,0 location so this is my code:
Run, C:\Program Files (x86)\ThunderSoft\DRM Protection\CPMaker.exe
WinMove, ahk_exe CPMaker.exe, , 0, 0
and this is Window Spy's information:
the first line of the code works but the moving part doesn't. I tried it with ahk_class TfrmMain too.
Problem solved by adding this line:
WinWait, ahk_exe CPMaker.exe, , 5
this line waits for the program to start the first parameter is WinTitle and the last one is the timeout in seconds.
the code still didn't work because of permission issues so I had to run it as admin, now it's working.
I'm new to powershell and as such finding my fingers are hitting wrong keys which produces the >> symbol. How to I 'undo' that to continue with the initial script?
E.g:
$i=0; get-childitem $dirname | foreach-object {...rest of script and I miss closing a bracket or something then get... >> and can't remove that and continue writing script.
I'm sure it's an easy key combination that I haven't found yet, but better than closing app and re-opening.
That symbol is a line continuation. Just keep typing as though you didn't hit Enter and it will treat everything as the full line you intended.
If you just want to "undo" and restart writing your script you can press:
Ctrl + C
For some reason, "C-z" is mapped to suspend-or-iconify-emacs and I can't seem to get it to rebind to something less annoying. (I like using ctrl-z for undo, but doing nothing would at least be better than suspending every time I accidentally hit the key)
I've tried doing it interactively:
M-x global-set-key, then Set key C-z to command: undo.
M-x describe-key-briefly gives me C-z runs the command suspend-or-iconify-emacs
I've tried going to the scratch buffer and evaluating:
(global-set-key (kbd "C-z") 'undo) and (global-set-key "\C-z" 'undo), and it is of course in my .xemacs/init.el file.
Nothing seems to actually rebind the key.
This is happening on XEmacs 21.5, in Fundamental mode. Any ideas on how to troubleshoot this?
edit: Ok here is a hack that gets around the problem by redefining the suspend function to undo:
(defun suspend-or-iconify-emacs () (interactive) (undo))
I can't actually suspend emacs anymore, but that's actually ok with me.
Try evaluating this:
(define-key global-window-system-map [(control z)] 'undo)
(assuming that you aren't running XEmacs in tty-mode, but I guess you are not, if you want to iconify :-))
I used C-h b to find out what *-map to modify.
I have the following code in my .emacs:
(global-set-key (kbd "C-z") 'eshell)
It will start an eshell, and it works.
The C-z combination is pretty standard on Unix/Linux, if you're working in a terminal with e.g. vi, lynx or mutt and presses C-z the program will suspend and you will be back in the shell. Issuing the 'fg' command will pop the program back again. As Emacs has its own shell, I like spawning that when pressing C-z in Emacs.
You can also add the following hook, that will remap C-z in the eshell. That way pressing C-z in the eshell with get you back to the buffer you were editing.
(add-hook 'eshell-mode-hook
(lambda ()
(local-set-key (kbd "C-z") 'bury-buffer)))
Put that at the end of your .xemacs/init.el :
(global-set-key (kbd "C-z") 'undo)
Or maybe you have a misconfigured keyboard or operating system.
Do C-h k C-z to see if xemacs really receives a C-z key.
I had the same problem with C-f. I wanted it to map to isearch-forward, but instead it kept moving one character forward.
I finally solved my problem by adding
(global-unset-key [?\C-f])
(global-set-key [?\C-f] 'isearch-forward)
Apparently the issue is that C-f (and C-z) is a "real" key, that is, it's something that a terminal recognizes (it's ASCII 0x06, 0x1a for C-z), so you need the "?\" in front of "C-f".
This is the only thing I got to work.
HTH
(EDIT: I should note that I use emacs, not xemacs)
I am trying to make elinks dump the web-page at the URL which starts at the current buffer position in vim (and ends at EOL), by mapping this keyboard shortcut and putting it in my .vimrc:
nmap owp :norm yE \| new \| .!elinks -dump #"<CR>
This yanks the rest of the line into the " register. Then it's supposed to open a new buffer and invoke elinks which should dump the rendered web-page into this new buffer. When I run the command the URL gets yanked, and that's it. New buffer does not open and elinks does not get invoked.
What am I doing wrong here?
Is there a smarter way to yank URLs
under the cursor? This method won't
work for URLs which occur in the middle of the line.
Never mind. Dug around in the vim manual and found some workarounds. One problem was with this:
.!elinks -dump #"<CR>
this won't work as expected. Everything after ! operator is passed to the shell verbatim by vim - so the register value will not be passed to elinks. Another problem is that the command separator somehow is not working after :norm yE. The final solution to get around these problems was this:
function! Browser ()
normal yE
new
execute ".!elinks -dump " . #"
set nomodified
endfunction
nmap owp :call Browser ()<CR>
Notice the use of execute to get around the limitation of "!" operator. I still need to figure out a solution for question 2 though.