orbs Posted February 5, 2014 Posted February 5, 2014 hello all, i'm trying to detect a long click on left or right Ctrl. my purpose is to assign a custom command to it, so instead pressing some weird keyboard combinations, i'll just need to click one of the Ctrl keys for ~300ms, and my script will perform some action (which i'll define later, intention to switch keyboard layout and typing direction simultaneously, similar to some Linux distros, which i find very convenient). i can pretty much detect the key press and the duration, with slight modification to the _IsPressed example: #include <Misc.au3> Local $hDLL = DllOpen("user32.dll") While True If _IsPressed("A2", $hDLL) Then ; left Ctrl was pressed ConsoleWrite("_IsPressed - left Ctrl key was pressed." & @CRLF) ; Wait until key is released. $hTimer=TimerInit() While _IsPressed("A2", $hDLL) Sleep(100) WEnd $nTime=TimerDiff($hTimer) ConsoleWrite("_IsPressed - left Ctrl key was released after "&$nTime&' ms' & @CRLF) ElseIf _IsPressed("1B", $hDLL) Then MsgBox(0, "_IsPressed", "The Esc Key was pressed, therefore we will close the application.") ExitLoop EndIf Sleep(250) WEnd DllClose($hDLL) but that does not exclude a combination click, like Ctrl+A. how would i detect when Ctrl only was pressed and released? or perhaps there is a completely different approach to this? thanks for any suggestion. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff
Danyfirex Posted February 5, 2014 Posted February 5, 2014 (edited) Hi. #include <Misc.au3> local $hDLL = DllOpen("user32.dll") Local $begin = 0 Local $dif =0 While 1 If _IsPressed(11) Then ConsoleWrite("CTRL was Pressed" & @crlf) While _IsPressed(11) ConsoleWrite("CTRL keep Pressed" & @crlf) Beep(1000, 100) WEnd ConsoleWrite("CTRL was Release" & @crlf) EndIf Sleep(100) WEnd saludos Edited February 5, 2014 by Danyfirex Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
BrewManNH Posted February 5, 2014 Posted February 5, 2014 Danyfirex, That script does practically the same thing as his script, except you look for any CTRL key instead of just the left one. Which is not what he's looking for. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Moderators JLogan3o13 Posted February 5, 2014 Moderators Posted February 5, 2014 (edited) I believe the OP is asking how to distinguish between pressing just CTRL, and CTRL used in a combination. You script works when CTRL is struck, but I can still use CTRL + A in combination. Edit: Too slow Edited February 5, 2014 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Danyfirex Posted February 5, 2014 Posted February 5, 2014 I got his answer wrong. sorry. Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now