AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

give different action to same hotkeys dynamically

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
kiu



Joined: 18 Dec 2005
Posts: 229
Location: Italy - Galatro(RC)

PostPosted: Thu Jan 19, 2006 10:14 am    Post subject: give different action to same hotkeys dynamically Reply with quote

This program is usefull if you make some task, for many times, in few minutes, with fewest hotkeys Laughing ,but maybe usefull in many other contexts.
Description:
this script assign different action to the same hotkeys(definied in file hotkeys.kiu that should look like this
Code:
[hks]
hks=XButton1|XButton2
).
To change current mode(the actual actions definied for current hotkeys) you must press wheel up or down while holding down right mouse button.
The modes are definied in modes.kiu:
Code:
send   ^c|send   {LButton}{CTRL down}v{CTRL up}|
send   ^x|send   !c|
send   ^s|send   ^z|
send   {Enter}|Send   {BS}|
send   {LButton}{Tab}|send   msgbox
modifier   CTRL|modifier   ALT|
modifier   SHIFT|modifier   WIN|
run   E:\ahk_scripts\new\ahk2exe.exe|run   E:\ahk_scripts\new\my_functions.exe|
run   E:\programmi\Aveicon\AveIcon.exe|run   E:\programmi\XnView-win-full\XnView\xnview.exe|
run   E:\ahk_scripts\new\mouse_modes|run   E:\ahk_scripts\new\radialm_new\source3|
run   E:\ahk_scripts\new|run   e:\programmi|
changeword   %§%|changeword   {   §   }|
thiskey|thiskey|

as you can see each line as the following sintax:
commandforfirstHK[%A_Tab%option] | commandforsecondHK[%A_Tab%option] |commandforthirdHK[%A_Tab%option] |
etc.,as many as number of hotkeys.
for now are implemented only send,run and some other command,but you can define yours.
This is the script:

Code:

;Author: Salvatore Agostino Romeo(romeo84ATgmail)
currentMode:=0
mode_on=False
initializeModes()
#SingleInstance force
Return

;toggle modes on/off
^!Space::
if(mode_on="True")
  {
    mode_on=False
    Menu,tray,Icon , mm_images\off.ico,,1
    ToolTip,Modes deactivated
    SetTimer,stoptt,3000
    deactivateModes()
  }
Else
  {
    mode_on=True
    activateModes()
    ToolTip,Modes activated
    SetTimer,stoptt,3000
    Menu,tray,Icon , mm_images\on.ico,,1
  }
Return
;change mode with rbutton down + wheel
WheelUp::
  GetKeyState,state,RButton,P
  if(state ="D")
  prevMode()
  Else
      Send,{WheelUp}
Return

WheelDown::
  GetKeyState,state,RButton,P
  if(state ="D")
  nextMode()
  Else
      Send,{WheelDown}
Return
;exit app
^Esc::
  ExitApp
Return

activateModes()
  {
    global
    IniRead, hks, hokeys.kiu, hks, hks
    StringSplit, hk, hks, |
    Loop,%hk0%
      {
        current_hk:=hk%A_Index%
        Hotkey,%current_hk%,takeAction,on
      }
    Return
  }
deactivateModes()
  {
    global
    IniRead, hks, hokeys.kiu, hks, hks
    StringSplit, hk, hks, |
    Loop,%hk0%
      {
        current_hk:=hk%A_Index%
        Hotkey,%current_hk%,off
      }
    Return
  }
nextMode()
  {
    global
    ;if disabled,enable modes
    if(currentMode=0)
      gosub,^!Space
    currentMode++
    if(currentMode>maxMode)
    currentMode:=maxMode
    StringSplit, butt, mode%currentMode%, |
    modi=
    numberofloop:=butt0-1
    Loop,%numberofloop%
      modi:=modi "`n-" hk%A_Index% ": " butt%A_Index%
    ToolTip,Mode --> %currentMode%:%modi%
    SetTimer,stoptt,3000
    Return
  }
prevMode()
  {
    global
    currentMode--
    if(currentMode<0)
      currentMode:=0
    ;if selected mode0,disable modes
    if(currentMode=0)
      gosub,^!Space
    StringSplit, butt, mode%currentMode%, |
    modi=
    numberofloop:=butt0-1
    Loop,%numberofloop%
      modi:=modi "`n-" hk%A_Index% ": " butt%A_Index%
    ToolTip,Mode --> %currentMode%:%modi%
    SetTimer,stoptt,3000
    Return
  }
;read modes from modes.kiu
initializeModes()
  {
    global
    FileRead, mode, modes.kiu
    StringSplit, mode, mode, `n
    maxMode:=mode0
    mode=
    mode0=thiskey|thiskey|
    Return
  }

takeAction:
  ;I don't know how some variables are blank at this point,so I re-initialize them
  initializeModes()
  IniRead, hks, hokeys.kiu, hks, hks
  StringSplit, hk, hks, |
  StringSplit, hkac, mode%currentMode%, |
  Loop,%hk0%
    {
      StringSplit,butt%A_Index% , hkac%A_Index%, %A_Tab%
      if(A_ThisHotkey=hk%A_Index%)
      {
        option:=butt%A_Index%2
        Label:=butt%A_Index%1
        Gosub,%Label%
        Break
      }
    }
Return
;unshow tooltip
stoptt:
  SetTimer,stoptt,off
  ToolTip,
Return

;starting with possible commands definied for modes
msg:
  MsgBox,% option
Return

thiskey:
  Send,{%A_ThisHotkey%}
Return

send:
  send,%option%
Return

run:
  run,%option%
Return

modifier:
  Send,{%option% down}
  KeyWait, %A_ThisHotkey%
  Send,{%option% up}
Return

changeword:
  Send,{LButton 2}
  tempx=%Clipboard%
  Clipboard=
  Send,^x
  StringSplit, op, option, §
  Send,%op1%%Clipboard%%op2%
  Clipboard=%tempx%
Return

For the script to work you must place in the same folder:
this script,modes.kiu,hotkeys.kiu and eventually some icons like described in code.
Finally this is a complete pack,comprehensive of icons and exe too
http://autohotkey.net/file/users/Members/kiu/mouse%20modes%200.5.1.zip
Please tell me about,especially if you doesn't understand what this script can do.
Back to top
View user's profile Send private message Visit poster's website
kiu



Joined: 18 Dec 2005
Posts: 229
Location: Italy - Galatro(RC)

PostPosted: Thu Jan 19, 2006 10:18 am    Post subject: Reply with quote

for exemple you can assign to numpad keys different task dynamically,or deactivate the script and use them normally in few seconds.These are corresponding files:

hotkeys.kiu
Code:
[hks]
hks=NumPad0|NumPad1|NumPad2|NumPad3|NumPad4|NumPad5|NumPad6|NumPad7|NumPad8|NumPad9


modes.kiu
Code:
send   ^c|send   {LButton}{CTRL down}v{CTRL up}|send   ^x|send   !c|send   ^s|send   ^z|send   {Enter}|Send   {BS}|send   {LButton}{Tab}|send   msgbox|
modifier   CTRL|modifier   ALT|modifier   SHIFT|modifier   WIN|run   E:\ahk_scripts\new\ahk2exe.exe|run   E:\ahk_scripts\new\my_functions.exe|run   E:\programmi\Aveicon\AveIcon.exe|run   E:\programmi\XnView-win-full\XnView\xnview.exe|run   E:\ahk_scripts\new\mouse_modes|run   E:\ahk_scripts\new\radialm_new\source3|run   E:\ahk_scripts\new|run   e:\programmi|


save the with correct name in the same folder of the script
Back to top
View user's profile Send private message Visit poster's website
kiu



Joined: 18 Dec 2005
Posts: 229
Location: Italy - Galatro(RC)

PostPosted: Thu Jan 19, 2006 10:35 am    Post subject: Reply with quote

the run options are some of my folders,change them with yours
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10471

PostPosted: Thu Jan 19, 2006 11:59 am    Post subject: Reply with quote

Looks interesting. To make your job easier, v1.0.41 (to be released today or tomorrow hopefully) will support contex sensitive hotkeys using the following syntax:

#IfWinActive Untitled - Notepad
#a::MsgBox This hotkey will be enabled only when the above window is active.
#b::MsgBox The same.
#IfWinActive ; Turn off the criteria.

One of the drawbacks is that such hotkeys use the keyboard hook and thus require Windows NT/2k/XP or later.
Back to top
View user's profile Send private message Send e-mail
Soapspoon



Joined: 23 Nov 2004
Posts: 8

PostPosted: Thu Jan 19, 2006 7:18 pm    Post subject: Reply with quote

Very interesting.

Looking forward very much to that feature, Chris! Keep up the good work -- you rock.
Back to top
View user's profile Send private message
Demokos as Guest
Guest





PostPosted: Thu Jan 19, 2006 8:48 pm    Post subject: Reply with quote

Very good news. Thanks Chris.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group