AutoHotkey Community

It is currently May 25th, 2012, 6:03 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: August 21st, 2007, 8:18 am 
Offline

Joined: May 17th, 2007, 12:07 pm
Posts: 1004
Location: Germany - Deutschland
Hallo,
there are several scripts to do some action for example when the right mouse button is double-clicked or is hold.
In this scripts you have to do it like this:
Code:
Rbutton::
   keywait, rbutton, t0.3
   if errorlevel = 1
   { ;right mouse button was hold for at least 0.3 seconds:
      do some action
   }
   else
   keywait, rbutton, d, t0.4
   if errorlevel = 0
   { ;right button was double-clicked:
                    do some other action
   }
   else
       mouseclick, right
Return


This Code could be much shorter and easier if there was a variable like A_LastKey and A_LastKeyDurability
So you could something like this:
Code:
RButton::
    keywait,,
    if A_LastKey=RButton and A_LastKeyDurability>=t.03
       ;RButton was hold at least for 0.3 seconds
    else if A_LastKey=Rbutton
       ;Rbutton was double-clicked
    else if A_LastKey=LButton
        ;RButton and then LButton was clicked
    else
       ;RButton was single short-clicked
RETURN


Is there already a method to do it as easy as you could do it with this two variables?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2007, 8:26 am 
Offline

Joined: June 6th, 2006, 3:19 pm
Posts: 1654
Location: Denmark
You are looking for PriorHotkey

_________________
RegEx Powered Dynamic Hotstrings
COM
AutoHotkey 2


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2007, 9:16 am 
Offline

Joined: May 17th, 2007, 12:07 pm
Posts: 1004
Location: Germany - Deutschland
Hy tonne,
but doesn´t A_PriorHotkey not only mean the last HOTKEY but not the last clicked key? And if not so, I have to use A_TickCount, but I haven´t a variable I don´t have to calculate with....?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2007, 9:26 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
"...doesn't A_PriorHotkey not only mean..." :?

A_PriorHotkey is indeed the last hotkey and not necessarily the last clicked key. It's usually sufficient to use A_TimeSincePriorHotkey to implement a short "time-out". If you are likely to click other keys/buttons before the "time-out" expires, register them as hotkeys:
Code:
~LButton::
~MButton::
  ; "~" means don't prevent the click from performing its native function
return
This way A_PriorHotkey will be updated with the name of the clicked button (including the "~" prefix, most likely.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2007, 9:29 am 
Offline

Joined: June 6th, 2006, 3:19 pm
Posts: 1654
Location: Denmark
Ah, sorry I didn't read your post thoroughly - I dont think what you are looking for exists at the moment.

_________________
RegEx Powered Dynamic Hotstrings
COM
AutoHotkey 2


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2007, 11:28 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8660
Location: Salem, MA
if you want to moniter for a certain key being hit previously, you can make it a hotkey (with the ~ modifier) so that A_PriorHotkey can see it.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2007, 5:07 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8660
Location: Salem, MA
you may also be able to do something with the keyboard hook.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2007, 4:00 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Is this, what you wanted?
Code:
#Persistent
hHookKeybd := DllCall("SetWindowsHookEx",Int,13, Uint,RegisterCallback("Keyboard","F") ; WH_KEYBOARD_LL = 13
            , UInt,DllCall("GetModuleHandle",UInt,0), UInt,0)
SetTimer Show, 100

Keyboard(nCode, wParam, lParam) {
   Global A_LastKey, A_LastKeyDuration
   Static DownTick
   If (wParam & 1) ; key UP
      A_LastKeyDuration := A_TickCount - DownTick
   Else {
      A_LastKey := NumGet(lParam+0) ; keycode
      DownTick := A_TickCount
   }
   Return DllCall("CallNextHookEx", UInt,0, Int,nCode, UInt,wParam, UInt,lParam)
}

Show:
   TrayTip,,A_LastKey = %A_LastKey%`nA_LastKeyDuration = %A_LastKeyDuration%
Return

In this form it might not be very useful. You probably want a ring buffer with the last few keys and their duration, because at a hotkey you will not see what happened before.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 30th, 2007, 12:01 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
I just had a novel idea... Why track the last [N] pressed keys, when AutoHotkey already does that? A while ago I wrote a function that gets a list of a script's variables by sending WM_COMMAND,ID_VIEW_VARIABLES to the script's main window and getting the text of Edit1. It was fairly simple to adapt it to get the text of the key history:
Code:
#InstallKeybdHook
^Space::MsgBox % GetKeyHistoryText()

GetKeyHistoryText()
{
    active_window := WinActive("A")
   
    dhw := A_DetectHiddenWindows
    DetectHiddenWindows, On

    Process, Exist
    hwnd := WinExist("ahk_class AutoHotkey ahk_pid " . ErrorLevel)
   
    was_active  := (hwnd=active_window)
    was_visible := was_active || DllCall("IsWindowVisible", "UInt", hwnd)
   
    if (!was_active)
    {   ; There seems to be no way to prevent KeyHistory from activating the window,
        ; so block user input to prevent accidental somethings.
        BlockInput, On
        if (!was_visible) {
            ; Seemed to work on XP, but not Vista:
            ;WinGetPos, x, y         ; remember position
            ;WinMove, -10000, -10000 ; should hopefully keep it out of the way...
            ; Works, but shows an empty frame on Vista:
            ;WinSet, Region, W0 H0 0-0
           
            WinGet, was_tp, Transparent
            WinSet, Transparent, 0
        }
    }
   
    KeyHistory
   
    ; Get the variable list text.
    ControlGetText, text, Edit1

    if (!was_active)
    {   ; un-block input
        BlockInput, Off
        if (!was_visible) {
            WinHide             ; restore invisibility
            ;WinMove, %x%, %y%   ; restore position
            ;WinSet, Region
            WinSet, Transparent, % (was_tp="") ? "OFF" : was_tp
        }
   
        ; Focus isn't always restored to the previously active window, so do this.
        WinActivate, ahk_id %active_window%
    }

    DetectHiddenWindows, %dhw%
   
    return text
}
Now all it needs is parsing code, to get the relevant information (keycodes, times, etc.) Unfortunately it does have the side-effect of deactivating the active window briefly...

Perhaps someone should start a thread on the Wish List forum to expose KeyHistory directly to the script (via a function, perhaps)? That's assuming such a thread doesn't already exist...

Edit: it does. (Also, I see you already had the idea of using KeyHistory,ControlGetText. ;))


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 30th, 2007, 3:21 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
See also here and there.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BobKnepper, BrandonHotkey, Google Feedfetcher, krthornton, Pulover, rbrtryn, toddintr, tomL, Yahoo [Bot] and 34 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group