 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
mindlesspuppet
Joined: 09 Aug 2008 Posts: 4
|
Posted: Sat Aug 09, 2008 4:08 pm Post subject: Simple Quick Copy script question |
|
|
I'm a super noob to autohotkey, so I apologize if this is a stupid question. I'm trying to write a basic script to quick copy full lines. In most applications you can select an entire sentence by clicking 3 or 4 times (varies). I'm currently using;
| Code: | #IfWinActive ahk_class MozillaUIWindowClass ; Quick Select Full Line Mozilla
!`::
send {LButton}{LButton}{LButton}
send ^c
return
#IfWinActive ahk_class OpWindow ; Quick Select Full Line Opera
!`::
send {LButton}{LButton}{LButton}
send c
return
#IfWinActive ahk_class SALFRAME ; Quick Select Full Line Open Office
!`::
send {LButton}{LButton}{LButton}{LButton}
send ^c
return |
Which works fine. However, I imagine there's a better way to do this using if/else statements. Also by using if/else I assume I could add addition window classes to common methods, instead of making a new entry for each. Can anyone help me out with this, it'd be greatly appreciated. |
|
| Back to top |
|
 |
Peter
Joined: 30 Dec 2005 Posts: 279
|
Posted: Sat Aug 09, 2008 4:46 pm Post subject: |
|
|
If-else statements are not apllicable here. The #IfWinActive is only there for the next hotkey(s) definition.
Once they are defined, those lines are normally never used anymore, not like an If-Else statement that is used to make a decision what code to use next. (At least in this script those lines are just used once)
You could rewrite your script a bit like this, but that's just a suggestion: (not tested) (btw, I guess that in the 2nd hotkey also ^c is needed and not c)
| Code: | GroupAdd, QuickCopyLines3, ahk_class MozillaUIWindowClass ; Mozilla
GroupAdd, QuickCopyLines3, ahk_class OpWindow ; Opera
GroupAdd, QuickCopyLines4, ahk_class SALFRAME ; Open Office
#IfWinActive ahk_group QuickCopyLines3 ; Quick Select Full Line with 3 clicks
!::
send {LButton 3}^c
return
#IfWinActive ahk_group QuickCopyLines4 ; Quick Select Full Line with 4 clicks
!::
send {LButton 4}^c
return |
|
|
| Back to top |
|
 |
mindlesspuppet
Joined: 09 Aug 2008 Posts: 4
|
Posted: Sat Aug 09, 2008 5:39 pm Post subject: |
|
|
[edt]
Actually doesn't seem that works. |
|
| Back to top |
|
 |
mindlesspuppet
Joined: 09 Aug 2008 Posts: 4
|
Posted: Sat Aug 09, 2008 6:19 pm Post subject: |
|
|
Okay I got it working using if statements. Though I still have one last problem. Heres the current code;
| Code: | !`::
WinGetClass, winclass, A
if winclass = SALFRAME
{
send, {LButton 4}^c
return
}
if winclass = OpWindow
{
send, {LButton 3}c
}
if winclass = MozillaUIWindowClass
{
send, {LButton 3}^c
}
return
|
What my problem is I'd like to add multiple window class to one of these methods, [for example if (winclass = MozillaUIWindowClass || Notepad++ || gdkWindowTopLevel) ... obviously this doesn't work, but hoping it makes the idea clear]. Are there any methods to do this? |
|
| Back to top |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1276
|
Posted: Sat Aug 09, 2008 10:33 pm Post subject: |
|
|
You can use the GroupAdd command to group together various window classes and use ahk_group instead, or use If Var in MatchList:
if winclass in MozillaUIWindowClass,Notepad++,gdkWindowTopLevel _________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
Peter
Joined: 30 Dec 2005 Posts: 279
|
Posted: Sat Aug 09, 2008 10:55 pm Post subject: |
|
|
@mindlesspuppet: Umm, you're not a super noob to Autohotkey as you say, because you made a good workaround for using If-else statements!
But you used again !`:: in your code. I guess your hotkey is only ! ? But I would say you have to look into expressions. | Code: | !::
WinGetClass, winclass, A
if (winclass = "SALFRAME")
send, {LButton 4}^c ; just 1 line of code -> no {} needed
else
if (winclass = "OpWindow" || winclass = "MozillaUIWindowClass")
send, {LButton 3}^c
else
sendraw, ! ; in case another window is active (e.g. Notepad)
return | PS: I've tested my previous code with Msgbox instead of Send, and it works for me, but maybe some misunderstanding about the script purpose. (While I was testing the other code, Serenity gave another good possibility) |
|
| Back to top |
|
 |
mindlesspuppet
Joined: 09 Aug 2008 Posts: 4
|
Posted: Sun Aug 10, 2008 10:44 am Post subject: |
|
|
Ahh jeez... forgot the quotes, that was the problem. Thanks for all the help!
Finished script;
| Code: | !`:: ;Hotkey is Alt+`(Tidle key)
WinGetClass, winclass, A
if (winclass = "SALFRAME")
{
KeyWait Alt
SetKeyDelay, 25
send, {LButton 4}^c
}
if (winclass = "OpWindow")
{
KeyWait Alt
SetKeyDelay, 25
send, {LButton 3}c ; Opera has a context menu on multiple clicks so just c
}
if (winclass = "MozillaUIWindowClass" or winclass = "Notepad++")
{
KeyWait Alt
SetKeyDelay, 25
send, {LButton 3}^c
}
return |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|