Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

HotKey UDF


  • Please log in to reply
164 replies to this topic

#41 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,574 posts

Posted 17 August 2009 - 03:54 PM

I'm trying to use HotKey.au3 to use Win-L to lock the computer and run the screen saver based on a post from Lej.

After pressing Win-L the computer locks and the screen saver runs. The problem is after I unlock the computer the keyboard locks up until I hit a modifier key (shift, ctrl, alt, or win).

Try this to recreate:

  • Have Notepad open when running the script
  • Run the script
  • Press Win-L
  • Unlock the computer
  • Try typing in Notepad
  • Typing "l" the first time will allow all the alphanumeric keys to work. Typing "l' the second time will lock the computer without pressing the Win key.
#include "HotKey.au3" #include "vkConstants.au3" HotKeySet("{Esc}", "_Quit") _HotKeyAssign(BitOr($CK_WIN, $VK_L), "ScreenSaver") While 1     Sleep(10) WEnd Func ScreenSaver()     Local Const $SC_SCREENSAVE = 0xF140     DllCall('user32.dll', 'int', 'LockWorkStation')      _SendMessage(_WinAPI_GetDesktopWindow(), $WM_SYSCOMMAND, $SC_SCREENSAVE, 0) EndFunc   ;==>ScreenSaver Func _Quit()     Exit EndFunc   ;==>_Quit


The problem isn't specific to Win-L. The same thing happens when I change the script to use Win-K (hitting "k" the second time will lock the computer)

Any ideas on what I'm doing wrong?

--Jeff

On XP everything works fine for me. What are your system?







#42 Jeff West

Jeff West

    Seeker

  • Active Members
  • 11 posts

Posted 17 August 2009 - 04:49 PM

I'm using AutoIt 3.3.0.0 (the latest non-beta version) and XP Professional with Service Pack 3.

I just tried running the same script in a Virtual PC running a clean build of XP Profession with Service Pack 2 and had the same problem. Same problem after compiling with 3.3.1.1 and even after rebooting.

No I'm really confused. Is anyone else able to duplicate the problem?

--Jeff

#43 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,574 posts

Posted 17 August 2009 - 05:07 PM

I'm using AutoIt 3.3.0.0 (the latest non-beta version) and XP Professional with Service Pack 3.

I just tried running the same script in a Virtual PC running a clean build of XP Profession with Service Pack 2 and had the same problem. Same problem after compiling with 3.3.1.1 and even after rebooting.

No I'm really confused. Is anyone else able to duplicate the problem?

--Jeff

Yes, I caught this bug. I think that is to blame Lock Workstation. Apparently stops working hook or something like that. I would think.

EDIT:

When I wrote this UDF, I not thought that it could be used for this purpose.

Edited by Yashied, 17 August 2009 - 05:13 PM.


#44 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,574 posts

Posted 17 August 2009 - 07:39 PM

Try this.

AutoIt         
#Include 'HotKey.au3' #Include 'vkConstants.au3' HotKeySet('{Esc}', '_Quit') _HotKeyAssign(BitOR($CK_WIN, $VK_L), 'ScreenSaver') While 1     Sleep(10) WEnd Func ScreenSaver()     Local Const $SC_SCREENSAVE = 0xF140     Local $Timer = TimerInit()     DllCall('user32.dll', 'int', 'LockWorkStation')     Do         Sleep(10)         If TimerDiff($Timer) > 1000 Then             Return         EndIf     Until _IsWorkstationLocked()     _SendMessage(_WinAPI_GetDesktopWindow(), $WM_SYSCOMMAND, $SC_SCREENSAVE, 0)     While _IsWorkstationLocked()         Sleep(10)     WEnd     DllCall('user32.dll', 'int', 'keybd_event', 'int', $VK_L, 'int', 0, 'int', 2, 'ptr', 0)     DllCall('user32.dll', 'int', 'keybd_event', 'int', $VK_LWIN, 'int', 0, 'int', 2, 'ptr', 0)     DllCall('user32.dll', 'int', 'keybd_event', 'int', $VK_RWIN, 'int', 0, 'int', 2, 'ptr', 0) EndFunc   ;==>ScreenSaver Func _IsWorkstationLocked()     Local Const $DESKTOP_SWITCHDESKTOP = 0x0100     Local $Result = False     $hDesktop = DllCall('user32.dll', 'hwnd', 'OpenDesktop', 'str', 'Default', 'int', 0, 'int', 0, 'int', $DESKTOP_SWITCHDESKTOP)     If Not @error Then         $Result = DllCall('user32.dll', 'int', 'SwitchDesktop', 'hwnd', $hDesktop[0])         $Result = Not $Result[0]         DllCall('user32.dll', 'int', 'CloseDesktop', 'hwnd', $hDesktop[0])     EndIf     Return $Result EndFunc   ;==>_IsWorkstationLocked Func _Quit()     Exit EndFunc   ;==>_Quit

EDIT:

This, incidentally, solves the Lej problem.

Edited by Yashied, 17 August 2009 - 08:02 PM.


#45 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,574 posts

Posted 17 August 2009 - 10:07 PM

Jeff West, I think the problem is solved?

#46 Jeff West

Jeff West

    Seeker

  • Active Members
  • 11 posts

Posted 17 August 2009 - 11:18 PM

It works great. Thank you for the time you put into solving this problem.

--Jeff

#47 grega

grega

    Seeker

  • Active Members
  • 8 posts

Posted 18 August 2009 - 04:52 AM

How can I use : Alt+RIGHT ?

#48 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,574 posts

Posted 18 August 2009 - 05:35 AM

What is "RIGHT"?

#49 grega

grega

    Seeker

  • Active Members
  • 8 posts

Posted 18 August 2009 - 06:18 AM

What is "RIGHT"?

It Is : RIGHT ARROW key (VK_RIGHT (0x27))
However, my problem is with "Alt" key using

Edited by grega, 18 August 2009 - 06:26 AM.


#50 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,382 posts

Posted 18 August 2009 - 06:30 AM

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

#51 grega

grega

    Seeker

  • Active Members
  • 8 posts

Posted 18 August 2009 - 07:03 AM

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 ?

#52 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,382 posts

Posted 18 August 2009 - 07:52 AM

Maybe something like this?

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

#53 grega

grega

    Seeker

  • Active Members
  • 8 posts

Posted 18 August 2009 - 08:00 AM

Maybe something like this?

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

Still not working

#54 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,382 posts

Posted 18 August 2009 - 08:05 AM

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

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

#55 grega

grega

    Seeker

  • Active Members
  • 8 posts

Posted 18 August 2009 - 08:18 AM

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

#56 grega

grega

    Seeker

  • Active Members
  • 8 posts

Posted 18 August 2009 - 08:18 AM

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 )

#57 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,574 posts

Posted 18 August 2009 - 08:34 AM

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')


#58 grega

grega

    Seeker

  • Active Members
  • 8 posts

Posted 18 August 2009 - 09:01 AM

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'

#59 rexx

rexx

    Wayfarer

  • Active Members
  • Pip
  • 65 posts

Posted 11 September 2009 - 10:07 AM

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


#60 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,574 posts

Posted 11 September 2009 - 05:32 PM

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:

AutoIt         
#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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users