Jump to content

Key status change(key up / down)


Recommended Posts

is there a way for autoit to detect the status of a specific key?

Example,

CODE
#include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1

Sleep ( 250 )

If _IsPressed("26", $dll) Then

MsgBox(0,"_IsPressed", "End Key Pressed")

Do

sleep(1)

Until (The key is released)

EndIf

WEnd

DllClose($dll)

[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]
Link to comment
Share on other sites

is there a way for autoit to detect the status of a specific key?

Example,

CODE
#include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1

Sleep ( 250 )

If _IsPressed("26", $dll) Then

MsgBox(0,"_IsPressed", "End Key Pressed")

Do

sleep(1)

Until (The key is released)

EndIf

WEnd

DllClose($dll)

Looks like your example script answers most of your question. Just change "Until (The key is released)" to "Until Not _IsPressed("26", $dll)"
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

Looks like your example script answers most of your question. Just change "Until (The key is released)" to "Until Not _IsPressed("26", $dll)"

true, but...I have many many many different possibilities for _IsPressed, not just "26"

[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]
Link to comment
Share on other sites

very helpful, thanks...but...It'll be hard for me to add it in... I have _ispressed used in my program about 75 times, and, Func _WaitRelease() doesnt seem to work because _ispressed is used so many different times, it doesnt stay a constant

[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]
Link to comment
Share on other sites

Come on, you can do it. :)

Basically what you want is, if any of my $keysArray _IsPressed(), _waitRelease() for that key.

:P

aha shit...I went and coppied / pasted, then deleted all of the _ispressed things, but, do you have a faster way? lol, it'd make my program faster, and would be appreciated, ;) lol

[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]
Link to comment
Share on other sites

Get DLLCallBack ... http://www.autoitscript.com/forum/index.ph...st&p=384128

And try this...

#include "DllCallBack.au3"
Global $KEY = 0

Global Const $WH_KEYBOARD_LL = 13
Global Const $WK_DOWN = 256
Global Const $WK_UP = 257

Global $hHook, $pStub_KeyProc

Global $pStub_KeyProc = _DllCallBack ("_KeyProc","int;ptr;ptr")

Global $hmod = DllCall("kernel32.dll","hwnd","GetModuleHandle","ptr",0)

Global $hHook = DllCall("user32.dll","hwnd","SetWindowsHookEx","int",$WH_KEYBOARD_LL, _
                                "ptr",$pStub_KeyProc,"hwnd",$hmod[0],"dword",0)
Global $buffer = ""

While 1
    Sleep(10)
WEnd

Func _KeyProc($nCode, $wParam, $lParam)
    Local $ret,$KEYHOOKSTRUCT
    
    If $nCode < 0 Then
        $ret = DllCall("user32.dll","long","CallNextHookEx","hwnd",$hHook[0], _
                        "int",$nCode,"ptr",$wParam,"ptr",$lParam)
        Return $ret[0]
    EndIf
    
    $KEYHOOKSTRUCT = DllStructCreate("dword;dword;dword;dword;ptr",$lParam)
    
    If $KEY = 0 Then
        If $wparam = $WK_DOWN Then
            $KEY = DllStructGetData($KEYHOOKSTRUCT,1)
            SplashTextOn("AutoIt3 Yahoo Group",$KEY & " DOWN" & @LF & Chr($KEY) & " DOWN",200,60)
        EndIf
    Else
        If $wparam = $WK_UP And (DllStructGetData($KEYHOOKSTRUCT,1) = $KEY) Then
            SplashTextOn("AutoIt3 Yahoo Group",$KEY & " UP" & @LF & Chr($KEY) & " UP",200,60)
            $KEY = 0
        EndIf
    EndIf
    
    $ret = DllCall("user32.dll","long","CallNextHookEx","hwnd",$hHook[0], _
                    "int",$nCode,"ptr",$wParam,"ptr",$lParam)
    Return $ret[0]
EndFunc

Func OnAutoItExit()
    DllCall("user32.dll","int","UnhookWindowsHookEx","hwnd",$hHook[0])
EndFunc

f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Link to comment
Share on other sites

Get DLLCallBack ... http://www.autoitscript.com/forum/index.ph...st&p=384128

And try this...

#include "DllCallBack.au3"
Global $KEY = 0

Global Const $WH_KEYBOARD_LL = 13
Global Const $WK_DOWN = 256
Global Const $WK_UP = 257

Global $hHook, $pStub_KeyProc

Global $pStub_KeyProc = _DllCallBack ("_KeyProc","int;ptr;ptr")

Global $hmod = DllCall("kernel32.dll","hwnd","GetModuleHandle","ptr",0)

Global $hHook = DllCall("user32.dll","hwnd","SetWindowsHookEx","int",$WH_KEYBOARD_LL, _
                                "ptr",$pStub_KeyProc,"hwnd",$hmod[0],"dword",0)
Global $buffer = ""

While 1
    Sleep(10)
WEnd

Func _KeyProc($nCode, $wParam, $lParam)
    Local $ret,$KEYHOOKSTRUCT
    
    If $nCode < 0 Then
        $ret = DllCall("user32.dll","long","CallNextHookEx","hwnd",$hHook[0], _
                        "int",$nCode,"ptr",$wParam,"ptr",$lParam)
        Return $ret[0]
    EndIf
    
    $KEYHOOKSTRUCT = DllStructCreate("dword;dword;dword;dword;ptr",$lParam)
    
    If $KEY = 0 Then
        If $wparam = $WK_DOWN Then
            $KEY = DllStructGetData($KEYHOOKSTRUCT,1)
            SplashTextOn("AutoIt3 Yahoo Group",$KEY & " DOWN" & @LF & Chr($KEY) & " DOWN",200,60)
        EndIf
    Else
        If $wparam = $WK_UP And (DllStructGetData($KEYHOOKSTRUCT,1) = $KEY) Then
            SplashTextOn("AutoIt3 Yahoo Group",$KEY & " UP" & @LF & Chr($KEY) & " UP",200,60)
            $KEY = 0
        EndIf
    EndIf
    
    $ret = DllCall("user32.dll","long","CallNextHookEx","hwnd",$hHook[0], _
                    "int",$nCode,"ptr",$wParam,"ptr",$lParam)
    Return $ret[0]
EndFunc

Func OnAutoItExit()
    DllCall("user32.dll","int","UnhookWindowsHookEx","hwnd",$hHook[0])
EndFunc
I like it!

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

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