Jump to content
Yashied

HotKey UDF

Recommended Posts

rexx

Cool!

Thanks i'll try it.

I would have done the following:

#Include <HotKey_17_beta.au3>

Global Const $VK_F12 = 0x7B

Global $Timer = 0

_HotKeyAssign($VK_F12, 'Message', BitOR($HK_FLAG_DEFAULT, $HK_FLAG_EXTENDEDCALL, $HK_FLAG_POSTCALL))

While 1
    Sleep(10)
WEnd

Func Message($iKey)
    If $iKey > 0 Then
        If ($Timer) And (TimerDiff($Timer) < 250) Then
            MsgBox(0, 'Hotkey Test Message', 'Hotkey has been pressed!')
            $Timer = 0
            Return
        EndIf
        $Timer = TimerInit()
    EndIf
EndFunc   ;==>Message

HotKey_17_beta.au3 you can download here.

Share this post


Link to post
Share on other sites
KinGzZz

hi, i am new to autoit, can somebody tell me the code for auto space bar and auto click number 0, like 0.1 second delay for each click. thanks

Edited by KinGzZz

Share this post


Link to post
Share on other sites
somdcomputerguy

hi, i am new to autoit, can somebody tell me the code for auto space bar and auto click number 0, like 0.1 second delay for each click. thanks

See this post, auto spacebar


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
XEyE

Thank you.

But the hotkeys do not work when they meet a loop in a funtion. Just simply try this:

#Include <HotKey.au3>


Global Const $VK_ESCAPE = 0x1B
Global Const $VK_F12 = 0x7B

; Assign "F12" with Message() and set extended function call
_HotKeyAssign($VK_F12, 'Message', BitOR($HK_FLAG_DEFAULT, $HK_FLAG_EXTENDEDCALL))

; Assign "CTRL-ESC" with Quit()
_HotKeyAssign(BitOR($CK_CONTROL, $VK_ESCAPE), 'Quit')

While 1
    Sleep(10)
WEnd

Func Message($iKey)
     MsgBox(0, 'Hot key Test Message', 'F12 (0x' & Hex($iKey, 4) & ') has been pressed!')
    while 1
        Sleep(100)
    WEnd
    
   
EndFunc   ;==>Message

Func Quit()
    Exit
EndFunc   ;==>Quit

Share this post


Link to post
Share on other sites
Yashied

Are you sure that this should work? Have you read the description about $HK_FLAG_NOOVERLAPCALL flag? Be sure to read. Anyway, you did a loop where it can not be done. This function is an interrupt for the main program, you must create another code design.

Edited by Yashied

Share this post


Link to post
Share on other sites
XEyE

Are you sure that this should work? Have you read the description about $HK_FLAG_NOOVERLAPCALL flag? Be sure to read. Anyway, you did a loop where it can not be done. This function is an interrupt for the main program, you must create another code design.

Sorry about that. Im just thinking if that can work, that will be great! ^^

And i got my new code design. Thanks.

#Include <HotKey.au3>


Global Const $VK_ESCAPE = 0x1B
Global Const $VK_F12 = 0x7B
Global Const $VK_F11 = 0x7A


_HotKeyAssign($VK_F12, 'Start')
_HotKeyAssign($VK_F11, 'Pause')

; Assign "CTRL-ESC" with Quit()
_HotKeyAssign(BitOR($CK_CONTROL, $VK_ESCAPE), 'Quit')
Global $flag = False
Global $counter = 1

While 1
    if $flag then 
        MainFunc()
    Else
        Sleep(10)
    EndIf
WEnd


Func Pause()
    $flag = False
EndFunc

Func Start()
    ;init()
    $flag = true
EndFunc

Func MainFunc()
    Sleep(100)
    $counter=$counter+1
    ToolTip($counter)
EndFunc   ;==>Message

Func Quit()
    exit
EndFunc   ;==>Quit

Share this post


Link to post
Share on other sites
Yashied

#Include <HotKey.au3>


Global Const $VK_ESCAPE = 0x1B
Global Const $VK_F12 = 0x7B
Global Const $VK_F11 = 0x7A


_HotKeyAssign($VK_F12, 'Start')
_HotKeyAssign($VK_F11, 'Pause')

; Assign "CTRL-ESC" with Quit()
_HotKeyAssign(BitOR($CK_CONTROL, $VK_ESCAPE), 'Quit')
Global $flag = False
Global $counter = 1

While 1
    if $flag then 
        MainFunc()
    Else
        Sleep(10)
    EndIf
WEnd


Func Pause()
    $flag = False
EndFunc

Func Start()
    ;init()
    $flag = true
EndFunc

Func MainFunc()
    Sleep(100)
    $counter=$counter+1
    ToolTip($counter)
EndFunc   ;==>Message

Func Quit()
    exit
EndFunc   ;==>Quit

This is the right approach.

Share this post


Link to post
Share on other sites
fisofo

@Yashied

Love the UDF so far! One thing, I have a specific window I am assigning hotkeys for, like this:

Opt("WinTitleMatchMode", 2)

_HotKeyAssign($VK_F1, 'CWDate', $HK_FLAG_EXTENDEDCALL, 'ConnectWise')
_HotKeyAssign($VK_F2, 'CWDate', $HK_FLAG_EXTENDEDCALL, 'ConnectWise') 
_HotKeyAssign($VK_F3, 'CWDate', $HK_FLAG_EXTENDEDCALL, 'ConnectWise')
_HotKeyAssign($VK_F4, 'CWDate', $HK_FLAG_EXTENDEDCALL, 'ConnectWise')

; For testing
Func CWDate($iKey)
    MsgBox(0, "", Hex($iKey, 4))
EndFunc

If I create a notepad document with "ConnectWise" in the title, it works fine, but the hotkey does not run at all for the program I want to use it for. Here's the program's window info:

>>>> Window <<<<
Title:  My Activities - ConnectWise v8.0
Class:  WindowsForms10.window.8.app.0.378734a
Position:   1912, 86
Size:   1296, 1000
Style:  0x17CF0000
ExStyle:    0x00050100
Handle: 0x0000000000040840

>>>> Control <<<<
Class:  WindowsForms10.window.8.app.0.378734a
Instance:   93
ClassnameNN:    WindowsForms10.window.8.app.0.378734a93
Advanced (Class):   [CLASS:WindowsForms10.window.8.app.0.378734a; INSTANCE:93]
ID: 2689752
Text:   
Position:   158, 172
Size:   1110, 777
ControlClick Coords:    403, 278
Style:  0x56010000
ExStyle:    0x00010000
Handle: 0x0000000000290AD8

Running MsgBox(0, "", WinActive("ConnectWise")) as a test while on the window returns "1" like it should, and WinGetTitle("[ACTIVE]") returns "My Activities - ConnectWise v8.0" like it should, so I'm not sure why the hotkey is not working.

I am running the latest (3.3.0.0), and I'm on Windows 7 x64. Any ideas?

EDIT: It appears the issue is not the above code, but hotkeys for this program *in general*... I cannot get any hotkeys to respond on this window. I will investigate to see what else I can find, although if you have ideas, I'd love to hear them!

Edited by fisofo

Share this post


Link to post
Share on other sites
fisofo

I figured out that the main issue was that of permissions, my lower-privileged script could not execute on higher privileged windows.

Despite that, I have run into problems with F1 - F4 not running the hotkeys assigned to them using this script when certain windows are open... I'm not sure why yet, but as soon as I use hotkeyset instead, they work fine. I'll have to dig into it more some other time as I've spent way too much time on this already, but I'll let you know if I ever figure out why... here's a snipet of the code I was testing though:

;~ _HotKeyAssign($VK_F1, 'CWDate')
;~ _HotKeyAssign($VK_F2, 'CWDate')
;~ _HotKeyAssign($VK_F3, 'CWDate')
;~ _HotKeyAssign($VK_F4, 'CWDate')
HotKeySet("{F1}", "CWDate")
HotKeySet("{F2}", "CWDate")
HotKeySet("{F3}", "CWDate")
HotKeySet("{F4}", "CWDate")

The hotkeyset work all the time, the hotkeyassign only seem to work on specific windows for just these specific keys (F1 to F4)

Share this post


Link to post
Share on other sites
ceoguang

Why is there no "del" key?

#include <HotKey.au3>

Global Const $VK_DELETE = 0x2E

_HotKeyAssign(BitOR($CK_CONTROL,$CK_ALT ,$VK_DELETE), 'MyFunc')

While 1
    Sleep(10)
WEnd

Func MyFunc()
    MsgBox(0, 'Test', 'pressed!')
EndFunc   ;==>MyFunc

Share this post


Link to post
Share on other sites
Yashied

Why is there no "del" key?

#include <HotKey.au3>

Global Const $VK_DELETE = 0x2E

_HotKeyAssign(BitOR($CK_CONTROL,$CK_ALT ,$VK_DELETE), 'MyFunc')

While 1
    Sleep(10)
WEnd

Func MyFunc()
    MsgBox(0, 'Test', 'pressed!')
EndFunc   ;==>MyFunc

You can not block CTRL-ALT-DEL.

Share this post


Link to post
Share on other sites
ceoguang

#Yashied

Really?

Then

You can specify a hot key, any key, including the CTRL-ALT-DEL, F12, WIN-...,

What does that mean?

Share this post


Link to post
Share on other sites
Yashied

Share this post


Link to post
Share on other sites
ceoguang

Disappointing........

Share this post


Link to post
Share on other sites
Mat

Disappointing........

I think its a very good idea. The amount of problems you could run into using something like BlockInput.

Share this post


Link to post
Share on other sites
fisofo

Fyi, I'm guessing you know this, but in case you don't, compiling a script on the most recent autoit gives me this:

HotKey.au3(194,56) : ERROR: Opt() called with illegal argument 1: "OnExitFunc"
Global $OnHotKeyExit = Opt('OnExitFunc', 'OnHotKeyExit')

EDIT: seems to work fine otherwise though!

Edited by fisofo

Share this post


Link to post
Share on other sites
Shafayat

Here is the fix. This will work with the 3.3.4.0

Nothing changed really. :mellow: Just thought this might help (other) noobs.

Download - Hotkeyfixed.zip


[Not using this account any more. Using "iShafayet" instead]

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

×