AutoHotkey Community

It is currently May 27th, 2012, 3:03 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: March 19th, 2010, 4:54 pm 
Offline

Joined: November 25th, 2004, 10:08 am
Posts: 57
I have the following code in a script:

Code:
#IfWinActive ahk_class Photoshop
   XButton1::   ; step back in history
      send, ^!z
   return
   
   Xbutton2::   ; step forward in history
      send, +^z
   return
   
   XButton1 & Wheelup::   ; scroll left
      send, ^{Wheelup}
   return
   
   XButton1 & Wheeldown::   ; scroll right
      send, ^{Wheeldown}
   return


So when I hold down XButton1 on my mouse and turn the wheel it scrolls horizontally as expected. However, if I just click and release XButton1 nothing happens. If I comment out the 2 "XButton1 & ..." hotkeys then XButton1 works by itself.

What have I done wrong here?

Thanks!


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 19th, 2010, 11:57 pm 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6071
Location: San Diego, California
tinaa wrote:
What have I done wrong here?

:arrow: http://www.autohotkey.com/docs/Hotkeys.htm#Symbols
search for "its key's native function will not be blocked"


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 20th, 2010, 12:24 am 
Offline

Joined: November 25th, 2004, 10:08 am
Posts: 57
Leef_me wrote:
tinaa wrote:
What have I done wrong here?

:arrow: http://www.autohotkey.com/docs/Hotkeys.htm#Symbols
search for "its key's native function will not be blocked"


Sorry, but I think I need some explanation as to how this applies to my example. I assume you're talking about this:

Quote:
~

When the hotkey fires, its key's native function will not be blocked (hidden from the system). In both of the below examples, the user's click of the mouse button will be sent to the active window:

~RButton::MsgBox You clicked the right mouse button.
~RButton & C::MsgBox You pressed C while holding down the right mouse button.

Notes: 1) Unlike the other prefix symbols, the tilde prefix is allowed to be present on some of a hotkey's variants but absent on others; 2) Special hotkeys that are substitutes for alt-tab always ignore the tilde prefix; 3) The tilde prefix is ignored on Windows 95/98/ME


Yet in my example I'm not trying to pass the native function (XButton1) to the application. It would be okay to do so as in this case it would be ignored, but that's not the intention of the script. Instead of sending XButton1 it should send ctrl-alt-z. It seems like the use of "XButton1 &" blocks the native function. The documentation of prefix keys explicitly mentions that this would happen unless you define the native key with its own hotkey, which in this case I have done.

In any case, I tried adding a "~" before each XButton1 in the example and it didn't help.

I'm wondering if it has something to do with these hotkeys being defined under a #IfWinActive section. Is this perhaps a bug?

Thanks.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 20th, 2010, 1:10 am 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6071
Location: San Diego, California
tinaa wrote:
Sorry, but I think I need some explanation as to how this applies to my example.

I apologize, my answer was a quick response and inaccurate. :oops:

Quote:
I'm wondering if it has something to do with these hotkeys being defined under a #IfWinActive section. Is this perhaps a bug?


Doubtful.

Are you sure that your hotkeys aren't firing?
I don't have a mouse with those button and don't have P.S.

I modified your script to generate printable characters with Notepad. Please try this out as a diagnostic.
Code:
#singleinstance force

#IfWinActive ahk_class Notepad
   RButton::   ; step back in history
      send, z
   return
     
   RButton & Wheelup::   ; scroll left
      send, x
   return
   
   RButton & Wheeldown::   ; scroll left
      send, y
   return


esc::exitapp

/* output results


zzzxxxxxxxxxxxxxxxx

zxxxxxyyyyyxxxxxyyyyyyyxxxxxxyyyyyyxxxxxxyyyyyyyxxxxxzzzzzzzzzz

zzzzxxxxxxxxyyyyyyyyyyxxxxxyyyyyyxxxxyyyyyxxxx
*/




I also wrote a diagnostic for the non-wheel keys (no #ifwinactive either)
Please disable the #ifwainactive and try it

Code:
#singleinstance force
#Persistent      ; <-------- you may need this
settitlematchmode 2 ; <----- easier to match a title, still must spell and CaPiTaLiZe correctly


^!z::
;msgbox ctl_alt_z
tooltip,ctl_alt_z
sleep,100
return

+^z::
;msgbox shift_ctl_z
tooltip,shift_ctl_z
sleep,100
return

esc::exitapp


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 20th, 2010, 8:19 am 
Offline

Joined: November 25th, 2004, 10:08 am
Posts: 57
Hi, thanks for the reply.

I tried your first script and it worked as expected. When I replaced RButton with XButton1, however, it only triggered the wheel combination hotkeys but not XButton1 by itself. When I then replaced XButton1 with XButton2, it again worked as expected (XButton2 fired its hotkey when pressed and release alone). So there's something about XButton1.

I did some further testing with this script:

Code:
#singleinstance force

#IfWinActive ahk_class Notepad
   XButton1::   ; step back in history
      send, X1{enter}
   return
     
   XButton1 & Wheelup::   ; scroll left
      send, X1&up{enter}
   return
   
   XButton1 & Wheeldown::   ; scroll left
      send, X1&down{enter}
   return

   XButton2::   ; step back in history
      send, X2{enter}
   return
     
   XButton2 & Wheelup::   ; scroll left
      send, X2&up{enter}
   return
   
   XButton2 & Wheeldown::   ; scroll left
      send, X2&down{enter}
   return

esc::exitapp


I first closed any other Autohotkeyscripts running than ran this test. To my surprise, it worked correctly for both XButton1 and XButton2. I then copied this code into my main script, and it stopped working with XButton1. So it seems like there must be something else in my script that's interfering with this. I'll have to go through it and see if I can find something relevant. I'll post back.

Thanks again.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2010, 8:41 am 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6071
Location: San Diego, California
At least you have a path to persue. I definitely would like to know the cause.

Best wishes.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2010, 8:58 am 
Offline

Joined: November 25th, 2004, 10:08 am
Posts: 57
Honestly, I can't find anything that should have this effect. I'm going to post my entire script (with one edit since I have a hotkey that enters in my email password). If you find you have a few minutes to kill, maybe you can find something I missed.

Code:
Process, Priority,, Realtime; Raise this script to Realtime priority

IfExist, Keyboard_mappings.ico
   menu, tray, icon, Keyboard_mappings.ico   ; sets the tray icon for this script

#SingleInstance force
; #InstallKeybdHook
; #InstallMouseHook

;set global path variables
perlpath = c:\perl\bin\perl.exe
itcpath = H:\Perl\itunes\iTunes_control\iTunes_control.pl

SetTitleMatchMode 2   ; in Autoexec section (before any #IfWinActive) will set the global title match mode to 2 (find string anywhere in title)
GroupAdd, ExplorerWindowsGroup, ahk_class CabinetWClass
GroupAdd, ExplorerWindowsGroup, ahk_class ExploreWClass
GroupAdd, ExplorerWindowsGroup, ahk_class #32770

GroupAdd, ExplorerandDesktopGroup, ahk_class CabinetWClass
GroupAdd, ExplorerandDesktopGroup, ahk_class ExploreWClass
GroupAdd, ExplorerandDesktopGroup, ahk_class Progman
return ; End of autoexecute section.

#IfWinActive ahk_class Notepad
   XButton1::   ; step back in history
      send, X1{enter}
   return
     
   XButton1 & Wheelup::   ; scroll left
      send, X1&up{enter}
   return
   
   XButton1 & Wheeldown::   ; scroll left
      send, X1&down{enter}
   return

   XButton2::   ; step back in history
      send, X2{enter}
   return
     
   XButton2 & Wheelup::   ; scroll left
      send, X2&up{enter}
   return
   
   XButton2 & Wheeldown::   ; scroll left
      send, X2&down{enter}
   return

#IfWinActive ahk_class Photoshop
   XButton1::   ; step back in history
      send, ^!z
   return
   
   Xbutton2::   ; step forward in history
      send, +^z
   return
   
   XButton1 & Wheelup::   ; scroll left
      send, ^{Wheelup}
   return
   
   XButton1 & Wheeldown::   ; scroll right
      send, ^{Wheeldown}
   return

#IfWinActive ahk_class iTunes
   XButton1 & Wheelup::
      send, +{Wheelup}
   return
   
   XButton1 & Wheeldown::
      send, +{Wheeldown}
   return
   

#IfWinActive ahk_class FM   ; 7-zip
   XButton1::backspace

#IfWinActive ahk_class XLMAIN   ; Excel
   ^0::   ; zoom to 100%
      send, !wj
   return

   XButton1 & Wheelup::
      SetScrollLockState, On
      send, {left}
      SetScrollLockState, Off
   return
   
   XButton1 & Wheeldown::
      SetScrollLockState, On
      send, {right}
      SetScrollLockState, Off
   return

#IfWinActive ahk_class CorelDRAW 15.0   ; CorelDRAW X5
   XButton1 & Wheelup::   ; scroll left
      send, ^{Wheelup}
   return
   
   XButton1 & Wheeldown::   ; scroll right
      send, ^{Wheeldown}
   return
   
   XButton1::   ; undo
      send, ^z
   return
   
   XButton2::   ; redo
      send, +^z
   return

#IfWinActive ahk_class AcrobatSDIWindow
   XButton1::
      send, !{Left}
   return

   XButton2::
      send, ~{Right}
   return

#IfWinActive .ahk - Notepad`+`+   ; provides context sensitive help for AutoHotKey in Notepad++ using the F1 key
   F1::
      ; The following values are in effect only for the duration of this hotkey thread.
      ; Therefore, there is no need to change them back to their original values
      ; because that is done automatically when the thread ends:
      SetWinDelay 10
      SetKeyDelay 0
      AutoTrim, On

      C_ClipboardPrev = %clipboard%
      clipboard =
      ; Use the highlighted word if there is one (since sometimes the user might
      ; intentionally highlight something that isn't a command):
      Send, ^c
      ClipWait, 0.1
      if ErrorLevel <> 0
      {
          ; Get the the word under containing the cursor
          SendInput ^{left}+^{right}^c
          ClipWait, 0.2
          if ErrorLevel <> 0  ; Rare, so no error is reported.
          {
              clipboard = %C_ClipboardPrev%
              return
          }
      }
      C_Cmd = %clipboard%  ; This will trim leading and trailing tabs & spaces.
      clipboard = %C_ClipboardPrev%  ; Restore the original clipboard for the user.
      Loop, parse, C_Cmd, %A_Space%`,  ; The first space or comma is the end of the command.
      {
          C_Cmd = %A_LoopField%
          break ; i.e. we only need one interation.
      }
      IfWinNotExist, AutoHotkey Help
      {
          ; Determine AutoHotkey's location:
          RegRead, ahk_dir, HKEY_LOCAL_MACHINE, SOFTWARE\AutoHotkey, InstallDir
          if ErrorLevel  ; Not found, so look for it in some other common locations.
          {
              if A_AhkPath
                  SplitPath, A_AhkPath,, ahk_dir
              else IfExist ..\..\AutoHotkey.chm
                  ahk_dir = ..\..
              else IfExist %A_ProgramFiles%\AutoHotkey\AutoHotkey.chm
                  ahk_dir = %A_ProgramFiles%\AutoHotkey
              else
              {
                  MsgBox Could not find the AutoHotkey folder.
                  return
              }
          }
          Run %ahk_dir%\AutoHotkey.chm
          WinWait AutoHotkey Help
      }
      ; The above has set the "last found" window which we use below:
      WinActivate
      WinWaitActive
      StringReplace, C_Cmd, C_Cmd, #, {#}
      send, !n{home}+{end}%C_Cmd%{enter}
   return

#IfWinActive ahk_class ConsoleWindowClass   ;Command Prompt Window
   $^x::   ;copy in command prompt windows
      send, {RButton}
   return

   $^v::   ;paste in command prompt windows
      SendInput {RButton}
   return

; no longer necessary on Vista
;#IfWinActive ahk_group  ExplorerandDesktopGroup
;   F2::   ;rename without modifying extension
;      SendInput {F2} ; Start rename/highlight name (if not already done so)
;      sleep 100
;      ControlGetFocus WhichControl, A
;      ControlGetText oldfilename, %WhichControl%, A
;      StringGetPos, periodpos, oldfilename, ., R1
;      if (NOT ErrorLevel) {   ; the period was found
;         periodfromright := StrLen(oldfilename) - periodpos
;         SendInput, +{left %periodfromright%} ; unhighlight the filename up to the first period from the right
;      }
;   return

#IfWinActive ahk_group ExplorerWindowsGroup
   $^n::      ; new folder in explorer windows (note: built in shortcut is Shift-Ctrl-N)
      SendInput ^a!ei      ; this should select all files then invert the selection, causing all files to be deselected enabling the following to always work
      SendInput !fw{enter}      ; file/new/folder
   return

   ^NumpadAdd::   ; Size all columns to fit in Windows Explorer
      send ^e{tab 3}   ; this makes sure you're in the file pane
      send, ^{NumpadAdd}
   return

   ^NumPadSub::   ; Select Details view then Size all columns to fit in Windows Explorer
      send, !vd
      send ^e{tab 3}   ; this makes sure you're in the file pane
      send, ^{NumpadAdd}
   return

   ^NumpadMult::   ; Select List view
      send, !vl
   return

   #v::      ; paste address from clipboard into address bar and go there
      send, !d^v{enter}
   return

#IfWinActive EndNote 8 -
   !+r::   ;sort references by Author then Year in Endnote8
      setkeydelay, -1
      send, !rssss{enter}{tab}{tab}!{down}{Home}f{enter}{tab}!{down}{home}y{enter}{enter}
   return

#IfWinActive   ; The following will be the default behaviour for ALL applications:========================================================!

;select all
^#a::
   send, ^{Home}^+{End}
return

;ping www.yahoo.com
#y::
   setkeydelay, 0
   ifwinexist, ping -n 10 www.yahoo.com
   {
      winactivate, ping -n 10 www.yahoo.com
   }
   else
   {
      run, cmd /c start "ping -n 10 www.yahoo.com" cmd,,Hide,PID
      Winwait, ping -n 10 www.yahoo.com
      winactivate, ping -n 10 www.yahoo.com
   }
   send, ping -n 10 www.yahoo.com{return}
return

; the following were defined for Microsoft Multimedia Keyboard (need to redifine for Logitech Wave keyboard)
; ;Messenger key launches powermarks
; SC105::
;    run, "C:\Program Files\Powermarks 3.5\pm.exe"
; return
;
; ;alt-ctrl-My Music opens MP3 folder
; !^SC13C::
;    run, "d:\mp3"
; return
;
; ;alt-ctrl-Media open Winamp
; !^VKB5SC16D::
;    run, "c:\program files\winamp\winamp.exe"
; return
; Browser_Home::
;    run, "C:\Program Files\Mozilla Firefox\firefox.exe"
; return


; save and reload current autohotkey script
!+s::
   send, ^s
   reload
return

; edit this script
!+e::
   edit
return

;paste at beginning of line
#!v::
   send, {home}^v
return

;copy path from windows explorer address bar
#!c::
   send,!d                  ; this selects the address bar
   send,{End}\               ; add final backslash
   send,^{Home}^+{End}            ; select all
   send,^c                  ; copy
   send,{Esc}{Esc}               ; dismiss drop down menu if appears and restores address bar to breadcrumb view
return

;open run dialog, paste from clipboard, and execute
^#!r::
   send,#r                  ; open run dialog
   winwait,Run
   winactivate,Run
   send,^v{enter}            ; paste and executeG:\Download\divx\
return

; note: I've redified Numpad to '=' in registry
NumpadSub::
   send -
return

^NumpadSub::
   send ^{NumpadSub}
return

NumpadSub & NumpadMult::
   send {^}
return

NumpadSub & NumpadDiv::
   send :
return

NumpadSub & Numpad0::
   send {space}
return

; note: I've redified Numpad to '=' in registry
NumpadSub & =::
   send {backspace}
return

NumpadSub & NumpadDot::
   send `,
return

NumpadSub & Numpad1::
   send AM
return

NumpadSub & Numpad2::
   send PM
return

NumpadSub & Numpad3::
   send E
return

NumpadSub & Numpad7::
   send (
return

NumpadSub & Numpad8::
   send )
return

; #F::   ;launch locate32
;    run, "C:\Program Files\Locate\Locate32.exe"
; return

!^h::   ;Random House Webster's Dictionary ver 1.0
   run, "C:\Program Files\RHWIN\EDTWIN.EXE"
return

^#!v::   ; add an "a" at end of filename and paste path at beginning (for saving modified photos in photoshop)
   send,{end}^{left}{left}a{home}^v
return

^#d::   ;insert date and time
   Send %A_YYYY%/%A_MM%/%A_DD% %A_Hour%:%A_Min%:%A_Sec%
return

!+d::   ;insert date in filename friendly format
   Send %A_YYYY%-%A_MM%-%A_DD%
return

!+t::   ;insert time in filename friendly format
   Send %A_Hour%-%A_Min%-%A_Sec%
return

^+[::   ;insert code block surrounded by curly brackets
   SendInput, {{}{Enter 2}{}}{up}{tab}
return

#!r::   ;start remote desktop for Serverette and reposition window
   run, "G:\Download\autohotkey\launchpriority scripts\serverette_movesize.ahk"
return

; need to redefine these for Logitech Wave keyboard
; ;iTunes automation:
; ;My Music key launches iTunes
; SC13C::   run, "c:\program files\itunes\itunes.exe"
; Media_Play_Pause::   run, %perlpath% %itcpath% Play,,hide
; Media_Prev::   run, %perlpath% %itcpath% Rewind,,hide
; Media_Next::   run, %perlpath% %itcpath% FastForward,,hide
; +Media_Play_Pause::   run, %perlpath% %itcpath% PlayPause,,hide
; Media_Stop::   run, %perlpath% %itcpath% Stop,,hide
; ^Media_Prev::   run, %perlpath% %itcpath% PlayerPosition -5,,hide
; ^Media_Next::   run, %perlpath% %itcpath% PlayerPosition +5,,hide
; #Media_Prev::   run, %perlpath% %itcpath% PlayerPosition -10,,hide
; #Media_Next::   run, %perlpath% %itcpath% PlayerPosition +10,,hide
; !Media_Prev::   run, %perlpath% %itcpath% PlayerPosition -30,,hide
; !Media_Next::   run, %perlpath% %itcpath% PlayerPosition +30,,hide
; +Media_Next::   run, %perlpath% %itcpath% NextTrack,,hide
; +Media_Prev::   run, %perlpath% %itcpath% BackTrack,,hide
;
; ;jump to specified position:
; #Media_play_Pause::
;    Loop
;    {
;       InputBox, position, iTunes: position to skip to, [+/-][min:]sec,,250,125
;       if (ErrorLevel = 0)      ; OK was pressed (otherwise canceled or closed)
;       {
;          if RegExMatch(position,"^([+-])?(?:(\d+):)?(\d+)$")   ; make sure a valid target position was entered
;          {
;             run, %perlpath% %itcpath% PlayerPosition %position%,,hide
;             break
;          } else {
;             msgbox, ,iTunes: position,Invalid target position. Try Again.`n`nEg. 23:12 (skip to 23 min, 12 sec from start)`nEg. +12 (skip forward 12 sec)`nEg. -1:30 (skip back 1 min 30 sec)
;          }
;       } else {
;          break
;       }
;    }
; return


^!w::   ; open download folder
   run, "d:\download"
return

^!d::   ; open DOS Command Prompt
   run, "cmd"
return

^!n::   ; open notepad
   run, notepad.exe
return

#z::   ; open drive z: (mapped to \\router\f:\public share)
   run, z:
return

^#!p::   ; open pogram files
   run, c:\program files
return

#!p::   ; open pogram files
   run, c:\program files (x86)
return

^!p::   ; open process explorer
   run, "C:\program files (x86)\ProcessExplorer\procexp.exe"
return

^!k::   ; open turbopasswords
   run, "C:\Program Files (x86)\Chapura\TurboPasswords\TurboPasswords.exe"
return

#backspace::   ; open device manager
   run, devmgmt.msc
return

^!g::   ;open Registrar Registry Manager
   run, "C:\program files\Registrar Registry Manager\rr.exe"
return

#!n::   ; open nero
   run, "C:\Program Files\Nero\Nero 7\Core\nero.exe"
return

#!w::   ; open Microsoft Word
   run, "C:\program files (x86)\Microsoft Office\Office12\winword.exe"
return

#!e::   ; open Microsoft Excel
   run, "C:\program files (x86)\Microsoft Office\Office12\excel.exe"
return

; note: #1:: I'm reserving for the first icon on the quicklaunch toolbar which is the Colorvision color profile for Powerstrip (since that hotkey will work even for elevated applications)
#0::   ; open C:
   run, c:\
return

#2::   ; open d:
   run, d:\
return

#3::   ; open e:
   run, e:\
return

#4::   ; open f:
   run, f:\
return

#5::   ; open g:
   run, g:\
return

#6::   ; open h:
   run, h:\
return

#7::   ; open m:
   run, m:\
return

#8::   ; open n:
   run, n:\
return

^!a::   ; open Photoshop CS3
   run, c:\Program Files\Adobe\Adobe Photoshop CS3\Photoshop.exe
return

^!q::   ; open download/palm/!t5
   run, G:\download\palm\!T5 install
return

^+c::   ; reload corrected colours by loading PowerStrip Default Colour Scheme followed by ColorVision Colour Scheme
   run, "C:\Program Files\PowerStrip\PStrip.exe" /p:Color defaults
   run, "C:\Program Files\PowerStrip\PStrip.exe" /p:ColorVision
return
 #!d::   ; run CorelDRAW X5
   run, "C:\Program Files (x86)\Corel\CorelDRAW Graphics Suite X5\Programs\CorelDRW.exe"
return

^!=::
   send, {numlock}
return

^!o::   ; run Outlook or bring to front
   DetectHiddenWindows, On
   IfWinNotExist, ahk_class rctrl_renwnd32
      Run, "C:\Program Files\Microsoft Office\OFFICE12\Outlook.exe"
   Else
      DetectHiddenWindows, Off
   IfWinNotExist ahk_class rctrl_renwnd32
      {
      WinShow, ahk_class rctrl_renwnd32
      }
   WinActivate, ahk_class rctrl_renwnd32
   ; Else
      ; IfWinExist, ahk_class rctrl_renwnd32
         ; {
         ; WinMinimize, ahk_class rctrl_renwnd32
         ; ; WinHide, ahk_class rctrl_renwnd32
         ; }
return

; load default windows calculator
^!rwin::   ; since calculator has been redifined as RWin, this is ctrl+alt+calculator
   IfWinExist ahk_class CalcFrame
   {
      WinActivate ahk_class CalcFrame
   }
   else
   {
      run, "C:\Windows\system32\calc.exe"
   }
return

; load SpeedCrunch Calculator
^!c::
#c::
+RWin::      ; pause/break key + calculator key
   IfWinExist ahk_class QWidget
   {
      WinActivate ahk_class QWidget
   }
   else
   {
      run, "C:\Program Files (x86)\SpeedCrunch\speedcrunch.exe"
   }
return

; y:: send, {WheelLeft}
; u:: send, {WheelRight}

launch_media::
media_prev::send {Wheelleft}
media_next::send {Wheelright}

^![::
   send {WheelLeft}
return

^!]::
   send {WheelRight}
return

^#!a::   ; copy ahk_id of active window to clipboard
   WinGetClass, ahk, A
   clipboard = #IfWinActive ahk_class %ahk%
   msgbox, "#IfWinActive ahk_class %ahk%" has been copied to the clipboard.
return


Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2010, 9:15 am 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6071
Location: San Diego, California
tinaa wrote:
If you find you have a few minutes to kill, maybe you can find something I missed.


I've entered the bedtime zone so I'll prolly check it out tomolly.
May I ask what timezone you are in?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2010, 8:08 pm 
Offline

Joined: November 25th, 2004, 10:08 am
Posts: 57
I'm in EST... (Couldn't sleep yesterday night...)

Thanks.


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

Joined: November 25th, 2004, 10:08 am
Posts: 57
Okay, I've isolated the problem but I don't understand it.

My hint came from looking at the key history. Here is the history for pressing and releasing the XButton1 button in notepad using the script I posted above:

Code:
Window: D:\Documents\autohotkey\Keyboard mappings.ahk - AutoHotkey v1.0.48.05
Keybd hook: yes
Mouse hook: yes
Enabled Timers: 0 of 0 ()
Interrupted threads: 0
Paused threads: 0 of 0 (0 layers)
Modifiers (GetKeyState() now) =
Modifiers (Hook's Logical) =
Modifiers (Hook's Physical) =
Prefix key is down: no

NOTE: To disable the key history shown below, add the line "#KeyHistory 0" anywhere in the script.  The same method can be used to

change the size of the history buffer.  For example: #KeyHistory 100  (Default is 40, Max is 500)

The oldest are listed first.  VK=Virtual Key, SC=Scan Code, Elapsed=Seconds since the previous event.  Types: h=Hook Hotkey,

s=Suppressed (blocked), i=Ignored because it was generated by an AHK script, a=Artificial, #=Disabled via #IfWinActive/Exist.

VK  SC   Type   Up/Dn   Elapsed   Key      Window
-------------------------------------------------------------------------------------------------------------
05  000   s   d   0.64   XButton1          
05  000   #   u   0.28   XButton1   

Notice the "#" on the Type column for the XButton1 release. This suggests the release is inhibited by a #IfWinActive statement.

So I commented out all the #IfWinActive blocks except for the one for Notepad and suddenly it worked correctly. Then I started uncommenting them one by one until I found the one causing the problem. That one is the following:

Code:
#IfWinActive ahk_class FM   ; 7-zip
   XButton1::backspace


Finally, I uncommented all of them but just commented out the one above and now XButton1 works correctly in all the other apps.

Then I replaced the above block with this one:

Code:
#IfWinActive ahk_class FM   ; 7-zip
   XButton1::
      send, {backspace}
   return


and that seems to fix the problem as everything now works as expected.

Clearly XButton1::backspace is doing something that interferes with XButton1 as a prefix/modifier key, but I can't claim to understand exactly why that is...

Thanks.


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

Joined: April 8th, 2009, 7:49 pm
Posts: 6071
Location: San Diego, California
tinaa wrote:
I'm in EST... (Couldn't sleep yesterday night...)
thanks... just curious.

>600 lines :shock: perlpath :shock: no wonder it doesn't work :wink:

I notice that you have similar hotkey usage besides PhotoShop.
Do you have problems in these applications?
#IfWinActive ahk_class Notepad
#IfWinActive ahk_class iTunes
#IfWinActive ahk_class XLMAIN ; Excel
#IfWinActive ahk_class CorelDRAW 15.0 ; CorelDRAW X5

btw, my complimented in your script origanization & documetation.
Even thought it is >600 lines it is pretty easy to read.

I'm curious, can you provide more detail on what this comment in your script means?
>>; note: I've redified Numpad to '=' in registry

>>Honestly, I can't find anything that should have this effect.

Hmm, besides the above question, I have 3 paths to suggest:
1. there seems to be an undocumented misfunction that may make some scripts not work, or perhaps parts. it is usually rectified (inadvertently) by disabling parts of script until the offending line(s) are found and then retyping the lines (various methods may exist such as copying the 'good' lines to a new file and retyping the 'bad' line(s). :cry:

2. based on a few passes at your script I don't see anything that would have the effect. Have you tried rebooting lately ?

3. I propose using the divide and conquer"" method. The following are steps to my version of this.

a. open another blank *.ahk and copy/paste the contents into the blank
(better yet -- copy the script as you published it in this thread, save/close/run/test Does it pass/fail the PS tests?

b. delete everything below this line save/close/run/test
#IfWinActive ; The following will be the default behaviour for ALL applications:========================================================!

c. if 'b' step passes. re-add sections until it fails
if 'b' step fails. continue removing sections'(from the bottom) until it passes.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2010, 1:19 am 
Offline

Joined: November 25th, 2004, 10:08 am
Posts: 57
I guess you missed my last post as I did find and detail the cause of the problem, although I don't quite understand why it caused the problem.

Yes, it's a long script but actually not that complex when you look at it. There's a lot of white space/comments and it's mostly just keyboard/mouse hotkeys (tailored for specific apps as necessary) which make my life easier in the long run...

Some of it (like the stuff pointing to perl scripts to make iTunes work) is inherited from older versions of the script and no longer used. There were also a bunch of references to programs I no longer use, so I actually went through it and trimmed the dated stuff finally after looking it at again...

Quote:
I'm curious, can you provide more detail on what this comment in your script means?
>>; note: I've redified Numpad to '=' in registry


The comment is to remind myself of what I've done. I used the registry key redefinition trick (it's documented in the manual and elsewhere, although I just use a little utility called "keytweak") to redefine the numberlock key as an "=" key (rather than use an autohotkey hotkey). I never disable numlock so the key isn't very useful and remapping it to "=" is much more useful to me for entering Excel calculations and formulas, as I use Excel frequently. I also used the numpad "-" key as a modifier for various other keys on the number pad, again for making entering calculations and formulas in excel more efficient. I find this works quite well as I can hold the "-" key with my pinky and hit the second key with my index or middle finger.
Thanks for your help.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2010, 1:42 am 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6071
Location: San Diego, California
tinaa wrote:
I guess you missed my last post as I did find and detail the cause of the problem, although I don't quite understand why it caused the problem.
Yep, missed the post, rats!

Cograts on the find, and no I don't understand the "backspace' thingy.

Best wishes.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2010, 7:18 am 
Offline

Joined: November 25th, 2004, 10:08 am
Posts: 57
It doesn't seem to have anything to do with the backspace, but rather with use of the key::otherkey syntax for remapping. So long as that line is replaced with a standard hotkey to send a replacement key it doesn't interfere, but if I use the above syntax then it does. It's strange to me that this interferes because the remapping with this syntax is under a #IfWinActive block but it doesn't just affect that block but all of them...

I am starting to suspect that this may be an obscure bug after all...

Thanks again.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2010, 7:46 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
The behavior is not related to the #IfWin directive.

AHK Help File wrote:
When a script is launched, each remapping is translated into a pair of hotkeys. For example, a script containing a::b actually contains the following two hotkeys instead:
Code:
*a::
SetKeyDelay -1   ; If the destination key is a mouse button, SetMouseDelay is used instead.
Send {Blind}{b DownTemp}  ; DownTemp is like Down except that other Send commands in the script won't assume "b" should stay down during their Send.
return

*a up::
SetKeyDelay -1  ; See note below for why press-duration is not specified with either of these SetKeyDelays.
Send {Blind}{b Up}
return


You can reproduce the behavior in this code.
Code:
a::b ;remap
a & b::MsgBox,% A_ThisHotkey ;prefix
The remapped a appears to do nothing because the prefix a blocks its down event, so only the a up hotkey fires, which in turn only produces b up, which produces nothing.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: rbrtryn, Yahoo [Bot] and 29 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