AutoHotkey Community

It is currently May 27th, 2012, 8:47 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: July 10th, 2006, 1:15 am 
Offline

Joined: July 6th, 2006, 7:26 pm
Posts: 48
Location: Poland
This function returns string with all pressed keys separated by spaces.
It is usable if you want to check if some extra keys are pressed simultaneously with hotkey key.

Code:
GetPressedKeys(gpk_mode = "")   {
; ____________________________________________________________________
; Usage:   GetPressedKeys([gpk_mode])
;            gpk_mode   - if omitted logical state is given,
;                       if set to "P" physical state is given
; ____________________________________________________________________
; TODO: add ALL missing keys as SCnnn (or maybe better as VKnn?)
; ____________________________________________________________________

   gpk_AllKeyNames := "` 1 2 3 4 5 6 7 8 9 0 - = q w e r t y u i o p [ ] \ a s d f g h j k l `; ' "" z x c v b n m , . / "
      . "LButton RButton MButton XButton1 XButton2 "            ; WheelDown WheelUp
      . "F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 "
      . "Space Tab Enter Esc Backspace Delete Insert Home End PgUp PgDn Up Down Left Right "
      . "NumpadDiv NumpadMult NumpadAdd NumpadSub NumpadEnter "
      . "NumpadDel NumpadIns NumpadClear NumpadUp NumpadDown NumpadLeft NumpadRight NumpadHome NumpadEnd NumpadPgUp NumpadPgDn "
      . "Numpad0 Numpad1 Numpad2 Numpad3 Numpad4 Numpad5 Numpad6 Numpad7 Numpad8 Numpad9 NumpadDot "
      . "ScrollLock CapsLock NumLock AppsKey "
      . "LWin RWin LControl RControl LShift RShift LAlt RAlt "
      . "PrintScreen CtrlBreak Pause Break "
      . "Help Sleep Browser_Back Browser_Forward Browser_Refresh Browser_Stop Browser_Search Browser_Favorites Browser_Home "
      . "Volume_Mute Volume_Down Volume_Up Media_Next Media_Prev Media_Stop Media_Play_Pause Launch_Mail Launch_Media Launch_App1 Launch_App2"
       
   loop parse, gpk_AllKeyNames, %A_Space%
      if (GetKeyState(A_LoopField, gpk_mode))
         gpk_pressed_keys:=gpk_pressed_keys . " " . A_LoopField

   if (A_AutoTrim = "Off") {
      AutoTrim, On
      gpk_pressed_keys = %gpk_pressed_keys%
      AutoTrim, Off
   }
   else
      gpk_pressed_keys = %gpk_pressed_keys%

   return gpk_pressed_keys
}


Remarks:
- only AHK's documented keys are detected; some keyboard's custom keys shall be added by SCnnn or VKnn codes
- full names of keys are used (Backspace instead of BS) except Esc
- generic/neutral Control, Alt, Shift keys are not present; use Left and Right pairs instead

Example of usage:
Code:
RButton::
   if (GetPressedKeys("P")="RButton")               ; RButton is pressed alone, so simulate clicks
      Send {o down}{LButton down}
   else                                             ; other keys are pressed simultaneously with RButton; so don't simulate custom clicks
      Send {RButton down}
RButton up::
   ...


If anyone have some comments or sugestion, feel free to post it here.

Regards,
Jav!

- update1: I have found that WheelDown and WheelUp keys after use aren't up, so I comment it.
(- update2: performance - coming soon)


Last edited by Tester on July 11th, 2006, 12:21 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 10th, 2006, 1:39 am 
Offline

Joined: June 8th, 2006, 2:41 am
Posts: 285
nice script, thx for sharing it


Last edited by d-man on July 12th, 2006, 1:47 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 10th, 2006, 9:22 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Interesting and useful. Of course, one can shorten the list for better performance.
Note that you could have used continuation section instead of a big string concatenation: it would have been more readable and easier to type (and it is faster, although it has little impact here).
Oh, and it might be interesting to declare it static, in case the function is called frequently. I don't know how static variables are handled in AutoHotkey, I fear that it would evaluate each time if written simplisticly. But a way to be sure it is evaluated only once is to use something like:
Code:
GetPressedKeys(gpk_mode = "")
{
   static gpk_AllKeyNames
   If gpk_AllKeyNames =
      gpk_AllKeyNames =
( Join`s
`` 1 2 3 4 5 6 7 8 9 0 - = q w e r t y u i o p [ ] \ a s d f g h j k l ; ' " z x c v b n m , . /
LButton RButton MButton WheelDown WheelUp XButton1 XButton2
etc.
)
; [...]
}

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Lost he he
PostPosted: July 12th, 2006, 10:11 am 
I'm fairly new to this and I'm trying to create some scripts to become more familiar with the commands. I try to run this and it doesn't do anything. I also tried adding FileAppend in hopes that it would send the pressed keys to a .txt file however I cannot figure it out. Anyone wanna help a new guy?


Report this post
Top
  
Reply with quote  
 Post subject: Re: Lost he he
PostPosted: July 12th, 2006, 11:19 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
ribbs2521 wrote:
I try to run this and it doesn't do anything.
It is just a function definition, you have to call the function to get the result. See the "Example of usage".

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 19th, 2010, 7:52 am 
Offline

Joined: October 27th, 2006, 10:12 am
Posts: 649
PhiLho wrote:
Note that you could have used continuation section instead of a big string concatenation: it would have been more readable and easier to type (and it is faster, although it has little impact here).
How can continuation sections be used to compose Latex codes with AutoHotkey, usually if you just paste any Latex code into such continuation sections it will end up with some error message in AHK.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 19th, 2010, 4:13 pm 
Offline
User avatar

Joined: December 5th, 2010, 7:19 pm
Posts: 311
Hello AHK Designers.

I got something that you should take a look at.

Tester wrote it.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, tomoe_uehara, Xx7 and 7 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