Jump to content

User set hotkey


Recommended Posts

I have a GUI and I want to implement a way to set a hotkey for macros that I have already programmed. the macros are chosen from a list. I saw on many GUIs before -not from autoit - where if a user presses a button it will appear in an input box and they can save the hotkey for that task or function. here is what I have so far, it's very disorganized though - it's just the rough draft to help me tweak the programming until I get the desired result. I'm sure there is a much easier way then I have went about it. I built a list to convert all the _ispressed values from misc.au3 to a format which hotkeyset() will accept. I have included what's in my ini file at the bottom in the comment section. Can anyone help me please?

#include<misc.au3>
GUICreate("shit",200,200,200,200)
HotKeySet("{NUMPADADD}","set")
GUIsetstate()
call("readkeylist")
Local $hotkey
Local $nodubs
$c=0
$loop=0
while $loop=0
    for $i = 1 to 149
        if _IsPressed(hex($i)) Then
            if not StringRegExp($nodubs," "&$i&",") and $keylist[$i] <> "invalid hotkey" Then
;~              if $i = 16 or $i=17 or $i = 18 and Not StringRegExp($nodubs," 1[678],") Then   ;I want to configure it so it only accepts a key value of 16-18 if there is no other key value of 16-18 because those values are ctrl alt and shift. I just want to let the user use one of them for the hot keys. It would be nice to have it allow only a modifier, such as: ctrl, alt and shift, and 1 other key but I'll get to doing that later. 
                $hotkey=$hotkey&$keylist[$i]
                $nodubs=$nodubs&" "&$i&","
                msgbox (0,"key pressed",$hotkey)
;~              EndIf
            EndIf
;~          msgbox (0,"key pressed",hex($i),1)
;~          msgbox (0,"key pressed",$keylist[$i],1)
;~          $val_key=InputBox("key pressed","enter key value corresponding to send() command","")   ;this is what I used to build the ini file -
;~          IniWrite(@DesktopDir&"/this.ini","key",$i,$val_key)   ; - with this
;~          HotKeySet($keylist[$i],"quit")
;~          $nodubs=$nodubs&" "&$i&","
            sleep(200)
        EndIf
    Next
sleep(100)
    if $c=1 Then
        msgbox(0,"c=1","c=1"&" "&$hotkey)
        HotKeySet($hotkey,"quit")
;~      HotKeySet(,"quit")
        $loop=1
    EndIf
WEnd

while 1
    sleep(200)
WEnd

func quit()
    Exit
EndFunc



func readkeylist()
    for $i=0 to 149
        $keylist[$i]=iniread(@DesktopDir&"/this.ini","key",$i,"invalid hotkey")
    Next
EndFunc

func set()
    $c=1
EndFunc
#cs
[key]
65=a
13={enter}
1={mouseleft}
83=s
68=d
70=f
71=g
72=h
74=j
75=k
76=l
144={numlock}
90=z
88=x
67=c
86=v
66=b
78=n
77=m
16=!
17=^
18=+
32={space}
96={numpad0}
97={numpad1}
98={numpad2}
99={numpad3}
100={numpad4}
101={numpad5}
102={numpad7}
104={numpad8}
105={numpad9}
111={numpaddiv}
106={numpadmult}
109={numpadsub}
107={numpadadd}
110={numpaddot}
49=1
50=2
51=3
52=4
53=5
54=6
55=7
56=8
57=9
48=0
9={tab}
46={delete}
45={insert}
35={end}
112={f1}
113={f2}
114={f3}
115={f4}
116={f5}
117={f6}
118={f7}
119={f8}
120={f9}
121={f10}
122={f11}
123={f12}
44={printscreen}
145={scrolllock}
12=5
37={left}
38={up}
40={down}
39={right}
27={escape}
2={mouseright}
36={home}
81=q
87=w
69=e
82=r
84=t
89=y
85=u
73=i
79=o
80=p
#ce
Link to comment
Share on other sites

I tried to do something like this before, but found, to my dismay, that several of the punctuation keys are not the same IsPressed number across different languages. The best thing I was able to come up with was a function I just recently posted, which you can grab here.

And uh, why are you using call? That's not how you're supposed to run a function like that.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...