Sign in to follow this  
Followers 0
srikanthsurabhi

Custom HotKeys for Different Windows

2 posts in this topic

Hi All,

I am trying to Create HotKeys using HotKey.au3

I want to create them such that Same Function Key ( F1,F2,F3 ) etc runs differently for different window titles

Below is the code I wrote till now

#Include <Array.au3> ; to work on Arrays

#Include <String.au3> ; to use String related functions

#Include <Clipboard.au3>

#Include<HotKey.au3>

#include <Process.au3>

#Include <File.au3>

#Include <StructureConstants.au3>

#Include <WinAPI.au3>

#Include <WindowsConstants.au3>

Opt("WinTitleMatchMode",2)

Opt("MustDeclareVars", 1)

;Variables for the function No_Of_Rajini_Instances()

Dim $Rajini_Instances,$No_Of_Rajini_Instances,$Hotkey,$Function,$Windowtitle,$Rajini_Function_Mapping,$Current_Hot_Keys,$No_Of_Current_Hot_Keys,$i,$j

Dim $Current_Hot_Keys_Array[1000],$Current_Hot_Keys_String,$hotkeyindexnum,$functionindexnum,$Windowtitleindexnum

Dim $hotkeyindexnum_VK_F1

;***********************************Assigning Hotkeys using the library #Include<HotKey.au3>***************************

Global Const $VK_F1 = 0x70

Global Const $VK_F2 = 0x71

Global Const $VK_F3 = 0x72

Global Const $VK_F4 = 0x73

Global Const $VK_F5 = 0x74

Global Const $VK_F6 = 0x75

Global Const $VK_F7 = 0x76

Global Const $VK_F8 = 0x77

Global Const $VK_F9 = 0x78

Global Const $VK_F10 = 0x79

Global Const $VK_F11 = 0x7A

Global Const $VK_F12 = 0x7B

;***********************************Assigning Hotkeys using the library #Include<HotKey.au3>***************************

Func No_Of_Rajini_Instances()

$Rajini_Instances = _ArrayFindAll(ProcessList(),"Rajini_Main_File.exe",0,0,0,1,0); performing partial search using _ArraySearch ; this gives $variable a zerobased array

;_ArrayDisplay($Rajini_Instances);used this line to see the progress

$No_Of_Rajini_Instances = UBound($Rajini_Instances)

Return $No_Of_Rajini_Instances

EndFunc

If No_Of_Rajini_Instances() > 1 Then

MsgBox(0,"Rajini Says..","I'm already running on your system..")

Exit

Else

MsgBox(0,"Rajini Says..","I started working .. cool",5)

EndIf

FileOpen ( "C:\Users\surabhis\Desktop\TREnD-Apps-Matching\Rajini_Function_Mapping.txt" )

$Rajini_Function_Mapping = FileRead("C:\Users\surabhis\Desktop\TREnD-Apps-Matching\Rajini_Function_Mapping.txt" )

$Rajini_Function_Mapping = _StringExplode($Rajini_Function_Mapping,@LF) ; Zero based array

;_ArrayDisplay($Rajini_Function_Mapping) ;used this line to see the progress

Sleep(3000)

;While

$Windowtitle = WinGetTitle("[active]")

MsgBox(0,"Active Window is",$Windowtitle)

$Current_Hot_Keys = _ArrayFindAll($Rajini_Function_Mapping,$Windowtitle,0,0,0,1)

_ArrayDisplay($Current_Hot_Keys);used this line to see the progress

$No_Of_Current_Hot_Keys = UBound($Current_Hot_Keys)

MsgBox(0,"",$No_Of_Current_Hot_Keys);used this line to see the progress

$i=0

Do

$j = $Current_Hot_Keys[$i]

$Current_Hot_Keys_Array[$i] = $Rajini_Function_Mapping[$j]

$i = $i+1

Until $i = $No_Of_Current_Hot_Keys

_ArrayDisplay($Current_Hot_Keys_Array);used this line to see the progress;A maximum of Hundred Hot keys can be stored per Window

$Current_Hot_Keys_String = _ArrayToString($Current_Hot_Keys_Array,'=',0,$No_Of_Current_Hot_Keys)

MsgBox(0,"Hot Key String",$Current_Hot_Keys_String);used this line to see the progress

$Current_Hot_Keys_Array = _StringExplode($Current_Hot_Keys_String,'=')

_ArrayDisplay($Current_Hot_Keys_Array);used this line to see the progress;A maximum of Hundred Hot keys can be stored per Window;This is a Zero Based Array

$hotkeyindexnum_VK_F1 = _ArraySearch($Current_Hot_Keys_Array,"$VK_F1",0,0,0,1,1)

If $hotkeyindexnum_VK_F1 <> -1 Then

$functionindexnum = ($hotkeyindexnum_VK_F1+1)

$Windowtitleindexnum = ($hotkeyindexnum_VK_F1+2)

$hotkey = '$VK_F1'

$function = $Current_Hot_Keys_Array[$functionindexnum]

$Windowtitle = $Current_Hot_Keys_Array[$Windowtitleindexnum]

Else

EndIf

MsgBox(0,"Hotkey-Function",$hotkey&$function&@LF&$Windowtitle)

While 1

Sleep(10)

WEnd

_HotKeyAssign ($hotkey,$function,0,$Windowtitle)

Func image()

MsgBox(0,"Success","I'm Listening")

Send("R.A.J.I.N.I.")

EndFunc

Text file I am referring has below text in it

$VK_F1='image'="PuTTY"=

$VK_F2='sendcomment'="PuTTY"=

$VK_F1='image'="Rajini_Rocks.txt - Notepad"=

$VK_F2='sendcomment'="Rajini_Rocks.txt - Notepad"=

$VK_F3='routedocument'="Rajini_Rocks.txt - Notepad"=

Code is working till MsgBox(0,"Hotkey-Function",$hotkey&$function&@LF&$Windowtitle)

But not assigning hotkey dynamically.

Please let me know where I am going wrong

Thank you,

Srikanth Surabhi

Share this post


Link to post
Share on other sites



Hi All,

I am trying to Create HotKeys using HotKey.au3

I want to create them such that Same Function Key ( F1,F2,F3 ) etc runs differently for different window titles

Below is the code I wrote till now

#Include <Array.au3> ; to work on Arrays

#Include <String.au3> ; to use String related functions

#Include <Clipboard.au3>

#Include<HotKey.au3>

#include <Process.au3>

#Include <File.au3>

#Include <StructureConstants.au3>

#Include <WinAPI.au3>

#Include <WindowsConstants.au3>

Opt("WinTitleMatchMode",2)

Opt("MustDeclareVars", 1)

;Variables for the function No_Of_Rajini_Instances()

Dim $Rajini_Instances,$No_Of_Rajini_Instances,$Hotkey,$Function,$Windowtitle,$Rajini_Function_Mapping,$Current_Hot_Keys,$No_Of_Current_Hot_Keys,$i,$j

Dim $Current_Hot_Keys_Array[1000],$Current_Hot_Keys_String,$hotkeyindexnum,$functionindexnum,$Windowtitleindexnum

Dim $hotkeyindexnum_VK_F1

;***********************************Assigning Hotkeys using the library #Include<HotKey.au3>***************************

Global Const $VK_F1 = 0x70

Global Const $VK_F2 = 0x71

Global Const $VK_F3 = 0x72

Global Const $VK_F4 = 0x73

Global Const $VK_F5 = 0x74

Global Const $VK_F6 = 0x75

Global Const $VK_F7 = 0x76

Global Const $VK_F8 = 0x77

Global Const $VK_F9 = 0x78

Global Const $VK_F10 = 0x79

Global Const $VK_F11 = 0x7A

Global Const $VK_F12 = 0x7B

;***********************************Assigning Hotkeys using the library #Include<HotKey.au3>***************************

Func No_Of_Rajini_Instances()

$Rajini_Instances = _ArrayFindAll(ProcessList(),"Rajini_Main_File.exe",0,0,0,1,0); performing partial search using _ArraySearch ; this gives $variable a zerobased array

;_ArrayDisplay($Rajini_Instances);used this line to see the progress

$No_Of_Rajini_Instances = UBound($Rajini_Instances)

Return $No_Of_Rajini_Instances

EndFunc

If No_Of_Rajini_Instances() > 1 Then

MsgBox(0,"Rajini Says..","I'm already running on your system..")

Exit

Else

MsgBox(0,"Rajini Says..","I started working .. cool",5)

EndIf

FileOpen ( "C:\Users\surabhis\Desktop\TREnD-Apps-Matching\Rajini_Function_Mapping.txt" )

$Rajini_Function_Mapping = FileRead("C:\Users\surabhis\Desktop\TREnD-Apps-Matching\Rajini_Function_Mapping.txt" )

$Rajini_Function_Mapping = _StringExplode($Rajini_Function_Mapping,@LF) ; Zero based array

;_ArrayDisplay($Rajini_Function_Mapping) ;used this line to see the progress

Sleep(3000)

;While

$Windowtitle = WinGetTitle("[active]")

MsgBox(0,"Active Window is",$Windowtitle)

$Current_Hot_Keys = _ArrayFindAll($Rajini_Function_Mapping,$Windowtitle,0,0,0,1)

_ArrayDisplay($Current_Hot_Keys);used this line to see the progress

$No_Of_Current_Hot_Keys = UBound($Current_Hot_Keys)

MsgBox(0,"",$No_Of_Current_Hot_Keys);used this line to see the progress

$i=0

Do

$j = $Current_Hot_Keys[$i]

$Current_Hot_Keys_Array[$i] = $Rajini_Function_Mapping[$j]

$i = $i+1

Until $i = $No_Of_Current_Hot_Keys

_ArrayDisplay($Current_Hot_Keys_Array);used this line to see the progress;A maximum of Hundred Hot keys can be stored per Window

$Current_Hot_Keys_String = _ArrayToString($Current_Hot_Keys_Array,'=',0,$No_Of_Current_Hot_Keys)

MsgBox(0,"Hot Key String",$Current_Hot_Keys_String);used this line to see the progress

$Current_Hot_Keys_Array = _StringExplode($Current_Hot_Keys_String,'=')

_ArrayDisplay($Current_Hot_Keys_Array);used this line to see the progress;A maximum of Hundred Hot keys can be stored per Window;This is a Zero Based Array

$hotkeyindexnum_VK_F1 = _ArraySearch($Current_Hot_Keys_Array,"$VK_F1",0,0,0,1,1)

If $hotkeyindexnum_VK_F1 <> -1 Then

$functionindexnum = ($hotkeyindexnum_VK_F1+1)

$Windowtitleindexnum = ($hotkeyindexnum_VK_F1+2)

$hotkey = '$VK_F1'

$function = $Current_Hot_Keys_Array[$functionindexnum]

$Windowtitle = $Current_Hot_Keys_Array[$Windowtitleindexnum]

Else

EndIf

MsgBox(0,"Hotkey-Function",$hotkey&$function&@LF&$Windowtitle)

While 1

Sleep(10)

WEnd

_HotKeyAssign ($hotkey,$function,0,$Windowtitle)

Func image()

MsgBox(0,"Success","I'm Listening")

Send("R.A.J.I.N.I.")

EndFunc

Text file I am referring has below text in it

$VK_F1='image'="PuTTY"=

$VK_F2='sendcomment'="PuTTY"=

$VK_F1='image'="Rajini_Rocks.txt - Notepad"=

$VK_F2='sendcomment'="Rajini_Rocks.txt - Notepad"=

$VK_F3='routedocument'="Rajini_Rocks.txt - Notepad"=

Code is working till MsgBox(0,"Hotkey-Function",$hotkey&$function&@LF&$Windowtitle)

But not assigning hotkey dynamically.

Please let me know where I am going wrong

Thank you,

Srikanth Surabhi

Figured out how to achieve that .

It was not working for me initially because I already declared VK_F1 etc as constants.

Also I used While .. Wend at a wrong place..

Thank you,

Srikanth Surabhi

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0