Sign in to follow this  
Followers 0
karthikraju

IsPressed works for one key, but does not for a key combination?

9 posts in this topic

Hello,

Background

1) AutoIt : 3.3.8.1

2) OS : Windows XP SP3

Issue

I am attempting to create a set of keyboard shortcuts, as shown in the code below:

#include <misc.au3>

Local $hDLL = DllOpen("user32.dll")

while 1
HotKeySet ("a" , "_keyA")
wend

Func _keyA ()

; DOES work
; Wake + Left = Left
If _ispressed ("FF") Then
Send("{LEFT}")
Endif

; DOES NOT work
; Alt + Wake + a = Home
; If _ispressed ("FF") and _ispressed ("12") Then
; Send("{HOME}")
; Endif

EndFunc
DllClose($hDLL)

One of them, as indicated in the comment, works and sends a Left when pressing "Wake + a". The other one when sending "Alt + Wake + a" does not work. Could someone please let me know what is that I am doing wrong?

Thank you for your time.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

for a start.

#include <misc.au3>

Local $hDLL = DllOpen("user32.dll")
HotKeySet ("a" , "_keyA")
while 1
sleep(10)
wend

Func _keyA ()

; DOES work
; Wake + Left = Left
If _ispressed ("FF") Then
Send("{LEFT}")
Endif

; DOES NOT work
; Alt + Wake + a = Home
; If _ispressed ("FF") and _ispressed ("12") Then
; Send("{HOME}")
; Endif

EndFunc
DllClose($hDLL)

You do notset hotkey in a loop.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Sorry, I made a mistake with my first post. This code block

; DOES NOT work
; Alt + Wake + a = Home
; If _ispressed ("FF") and _ispressed ("12") Then
; Send("{HOME}")
; Endif

should have been as follows:

; DOES NOT work
; Alt + Wake + a = Home
If _ispressed ("FF") and _ispressed ("12") Then
Send("{HOME}")
Endif

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I never knew you could add keys together (FF) is that really wake And left?

Have you tried individual keys _Ispressed(wake) And _Ispressed(left) And _Ispressed(a)?

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

I never knew you could add keys together (FF) is that really wake And left?

Have you tried individual keys _Ispressed(wake) And _Ispressed(left) And _Ispressed(a)?

FF is for one key, and is the key code for a key on the keyboard I've. Sorry, I am only tentative that the modifier name is Wake. Besides, the help file with the documentation for _isPressed [1] shows that it takes the key code as the argument and not the modifier name. Isn't it so?

So, I tested the individual keys like you recommended as follows:

#include  <misc.au3>

Local $hDLL = DllOpen("user32.dll")

while 1
If _ispressed ("FF", $hDLL) and _ispressed (41, $hDLL) Then
Send("{LEFT}")
Endif
wend

DllClose($hDLL)

which produced the intended result, but with side effects. The outcome results in multiple Left key presses and when the key combination is released it leaves an "a".

And since you have opened the dll should it not be _Ispressed(key,$hDLL)?

Yes, indeed. Thanks.

[1] http://www.autoitscript.com/autoit3/docs/libfunctions/_IsPressed.htm

Share this post


Link to post
Share on other sites

#include "HotKey.au3" ;http://www.autoitscript.com/forum/topic/90492-hotkey-udf/

_HotKeyAssign(BitOR(0xFF, 0x12), "_toto", BitOR($HK_FLAG_NOOVERLAPCALL, $HK_FLAG_NOREPEAT))

While 1
    Sleep(1000)
WEnd

Func _toto()
    Send("{LEFT}")
EndFunc

Add $HK_FLAG_NOBLOCKHOTKEY in the BitOR if you want the hotkey to be non blocking.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Thank you Firefox.

I took your code and modified it as follows:

#include <Misc.au3>
#include <HotKey.au3>
#include <vkConstants.au3>

Local $hDLL = DLLOpen("user32.dll")

_HotKey_Assign($VK_LAUNCH_APP1, '_funcApp', $HK_FLAG_WAIT)
_HotKey_Assign(BitOR($CK_CONTROL, $VK_ESCAPE), 'funcQuit')

While 1
Sleep(1000)
WEnd

Func _funcApp()

; Send("{LEFT}"); DOES NOT work(!), when not commented
; Send("^{LEFT}"); DOES work, when not commented
; Send("^+{LEFT}"); DOES work, when not commented

If _isPressed("41", $hDLL) Then
; Send("{LEFT}"); IS NOT when "Hotkey & A"
Send("^{LEFT}") ; IS NOT invoked when "Hotkey & A"
Endif

EndFunc

Func funcQuit()
Exit ; DOES work
EndFunc

DllClose($hDLL)

As the inline comments show, the send "Left" does not work, but "Control + Left" and "Control + Shift + A" does. Also, I wanted to use the Hotkey and A to send "Left", but this doesn't work either.

Any input is appreciated.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

As the inline comments show, the send "Left" does not work, but "Control + Left" and "Control + Shift + A" does. Also, I wanted to use the Hotkey and A to send "Left", but this doesn't work either.

Any input is appreciated.

You can not use key combinations with combinations having in first key something else than Ctrl, Alt or Win.

I did not think to it when I gave you my example.

Let's go back to your example :

#include <Misc.au3>

;block the key
HotKeySet("{a}", "_toto")

Local $hDLL = DllOpen("user32.dll")

While 1
    Sleep(10)

    If _IsPressed("FF", $hDLL) And _IsPressed("41", $hDLL) Then ;keys are pressed
        While _IsPressed("FF", $hDLL) Or _IsPressed("41", $hDLL) ;wait for them to be released
            Sleep(10)
        WEnd

        Send("{LEFT}")
    EndIf
WEnd

Func _toto()
    ;
EndFunc

DllClose($hDLL)

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

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