Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

give different action to same hotkeys dynamically


  • Please log in to reply
5 replies to this topic
kiu
  • Members
  • 234 posts
  • Last active: Oct 10 2010 07:30 PM
  • Joined: 18 Dec 2005
This program is usefull if you make some task, for many times, in few minutes, with fewest hotkeys :lol: ,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
[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:
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:

;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
https://ahknet.autoh...modes 0.5.1.zip
Please tell me about,especially if you doesn't understand what this script can do.

kiu
  • Members
  • 234 posts
  • Last active: Oct 10 2010 07:30 PM
  • Joined: 18 Dec 2005
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
[hks]
hks=NumPad0|NumPad1|NumPad2|NumPad3|NumPad4|NumPad5|NumPad6|NumPad7|NumPad8|NumPad9

modes.kiu
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

kiu
  • Members
  • 234 posts
  • Last active: Oct 10 2010 07:30 PM
  • Joined: 18 Dec 2005
the run options are some of my folders,change them with yours

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
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.

Soapspoon
  • Members
  • 8 posts
  • Last active: Jan 19 2006 07:18 PM
  • Joined: 23 Nov 2004
Very interesting.

Looking forward very much to that feature, Chris! Keep up the good work -- you rock.

Demokos as Guest
  • Guests
  • Last active:
  • Joined: --
Very good news. Thanks Chris.