HotKey UDF

181 posts in this topic

Posted

According to UDF help-file for _ispressed() ALT = 12 => $VK_MENU = 0x12. msdn says "VK_MENU (0x12) (ALT key)".

I know this

Bat : _HotKeyAssign(BitOR($VK_MENU, $VK_RIGHT), 'Message', BitOR($HK_FLAG_DEFAULT, $HK_FLAG_EXTENDEDCALL)) does not want to work

_HotKeyAssign(BitOR($СK_MENU, $VK_RIGHT), 'Message', BitOR($HK_FLAG_DEFAULT, $HK_FLAG_EXTENDEDCALL)) too.

Can you give example for the use of Buttons' Alt ', together with any button ?

Share this post


Link to post
Share on other sites



Posted

Maybe something like this?

_HotKeyAssign(0x12+0x27, 'Message', BitOR($HK_FLAG_DEFAULT, $HK_FLAG_EXTENDEDCALL))

Share this post


Link to post
Share on other sites

Posted

Maybe something like this?

_HotKeyAssign(0x12+0x27, 'Message', BitOR($HK_FLAG_DEFAULT, $HK_FLAG_EXTENDEDCALL))

Still not working

Share this post


Link to post
Share on other sites

Posted

Your right, that one's a bugger >_<...

_HotKeyAssign(BitOR(0x27, $CK_ALT),'message', BitOR($HK_FLAG_DEFAULT, $HK_FLAG_EXTENDEDCALL))

Share this post


Link to post
Share on other sites

Posted

By the way :

HotKeys 'Ctrl' and 'Shift' working only with : $CK_CONTROL and $CK_SHIFT (bat no working with $VK_CONTROL and $VK_SHIFT )

Share this post


Link to post
Share on other sites

Posted

Maybe something like this?

_HotKeyAssign(0x12+0x27, 'Message', BitOR($HK_FLAG_DEFAULT, $HK_FLAG_EXTENDEDCALL))

Still not working

By the way :

HotKeys 'Ctrl' and 'Shift' working only with : $CK_CONTROL and $CK_SHIFT (bat no working with $VK_CONTROL and $VK_SHIFT )

Share this post


Link to post
Share on other sites

Posted

Still not working

By the way :

HotKeys 'Ctrl' and 'Shift' working only with : $CK_CONTROL and $CK_SHIFT (bat no working with $VK_CONTROL and $VK_SHIFT )

I suggest you read VERY CAREFULLY the documentation for _HotKeyAssign() within a UDF.

_HotKeyAssign(BitOR($CK_ALT, $VK_RIGHT), 'Message')

Share this post


Link to post
Share on other sites

Posted

I suggest you read VERY CAREFULLY the documentation for _HotKeyAssign() within a UDF.

_HotKeyAssign(BitOR($CK_ALT, $VK_RIGHT), 'Message')

Thanks,my mistake that I tried to use a non-existent constant: '$CK_MENU' instead of '$CK_ALT'

Share this post


Link to post
Share on other sites

Posted

Hi, I want to create a double click hotkey with your hotkeyset

And here's how I do it now.

It works but i want to know is there a better way to do this?

$iFlag = BitOR($iFlag, $HK_FLAG_EXTENDEDCALL)
Assign("HotkeyFunc" & $iKey, $sFunc, 2)
_HotKeyAssign($iKey, "HotkeyDouble", $iFlag)

Func HotkeyDouble($iKey)
	if $iPriorKey = $iKey and TimerDiff($iPriorKeyTime) < 250 then Call(Eval("HotkeyFunc" & $iKey))
	$iPriorKey = $iKey
	$iPriorKeyTime = TimerInit()
EndFunc

Share this post


Link to post
Share on other sites

Posted

Hi, I want to create a double click hotkey with your hotkeyset

And here's how I do it now.

It works but i want to know is there a better way to do this?

$iFlag = BitOR($iFlag, $HK_FLAG_EXTENDEDCALL)
Assign("HotkeyFunc" & $iKey, $sFunc, 2)
_HotKeyAssign($iKey, "HotkeyDouble", $iFlag)

Func HotkeyDouble($iKey)
	if $iPriorKey = $iKey and TimerDiff($iPriorKeyTime) < 250 then Call(Eval("HotkeyFunc" & $iKey))
	$iPriorKey = $iKey
	$iPriorKeyTime = TimerInit()
EndFunc

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

Posted

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

Posted

very good! :D

Share this post


Link to post
Share on other sites

Posted (edited)

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

Posted

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

Share this post


Link to post
Share on other sites

Posted

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

Posted (edited)

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

Posted

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

Posted

#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

Posted (edited)

@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

Posted

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

Posted

Working on AutoIt 3.3.0.0, Windows XP Service Pack 2, Portuguese (Brazil) version.

Thanks!!! :)

Share this post


Link to post
Share on other sites

Posted

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

Posted

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

Posted

#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

Posted

You can specify a hot key for CTRL-ALT-DEL but not block it. This is impossible in Windows NT-based systems (I think). Moreover there are no good reasons to do so.

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

  • Recently Browsing   0 members

    No registered users viewing this page.