Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

KeyWait Question


  • Please log in to reply
7 replies to this topic
Dan86
  • Members
  • 11 posts
  • Last active: Nov 10 2014 04:51 AM
  • Joined: 11 Oct 2014

Is there a way to set KeyWait to ANY Key stroke?

 

I do not want any specific key, however any 2 Key Strokes.

 

So if I hit U + E, or A + I, or S + 9.

 

I am trying to get an auto-return for Excel data input...

 

I have numerous 2-digit alphanumeric codes, and after I enter a 2-digit code, I want the {enter} button to be sent.


Am I going about this the wrong way perhaps?



scriptor
  • Members
  • 668 posts
  • Last active: Feb 15 2016 01:02 AM
  • Joined: 20 Jun 2013

can you post your code so far?



Dan86
  • Members
  • 11 posts
  • Last active: Nov 10 2014 04:51 AM
  • Joined: 11 Oct 2014

I am only just starting this project, I have not yet figured out how to have it interact with Excel, right now I am just trying to get the KeyWait, or something else to work that I can type any 2 keys, have it hit Enter, until I close the box.

note - this is not working at all right now

InputBox, Number1, How many characters, Enter number of Letters., , 250, 150
if ErrorLevel
    MsgBox, CANCEL was pressed.
else
    MsgBox,4,OK, Hit Yes to Start "Auto-Enter" after %Number1% are typed `nHit No to cancel
		IfMsgBox Yes
			KeyWait,
			KeyWait,
			Send {Enter}			
		IfMsgBox No
			MsgBox You Cancelled.
return


Dan86
  • Members
  • 11 posts
  • Last active: Nov 10 2014 04:51 AM
  • Joined: 11 Oct 2014

Perhaps Input command would work better?



scriptor
  • Members
  • 668 posts
  • Last active: Feb 15 2016 01:02 AM
  • Joined: 20 Jun 2013

If I'm understacnding you correctly, after you press the second key, you want 'enter' to be sent automatically? If so, I don't think KeyWait is what you're looking for.. is this correct? 



scriptor
  • Members
  • 668 posts
  • Last active: Feb 15 2016 01:02 AM
  • Joined: 20 Jun 2013

here is a script that waits for any 2 keys to be pressed quickly in succession. For example, if you want it to work within your script, then when you press any 2 keys quickly (for example press 5 and then 9 quickly, or press A and then 4, or U and then F5), it will send enter. Doesn't matter what 2 keys have been pressed, so long as they are specified in the initial code. You can trim down that initial hotkey menu to just a few keys if you only want the code to work with just a few keys (1, 2, 3, 4, 5, 6, 7, 8, 9, 0 for example - just remove all other keys from the code). You can significantly trim this code down by removing any of the initial hotkeys that you might never use.  I don't know if this is what you want or how you could tie it into your code, but try it out:

#Persistent
#NoEnv


~a:: gosub, RunKey
~b:: gosub, RunKey
~c:: gosub, RunKey
~d:: gosub, RunKey
~e:: gosub, RunKey
~f:: gosub, RunKey
~g:: gosub, RunKey
~h:: gosub, RunKey
~i:: gosub, RunKey
~j:: gosub, RunKey
~k:: gosub, RunKey
~l:: gosub, RunKey
~m:: gosub, RunKey
~n:: gosub, RunKey
~o:: gosub, RunKey
~p:: gosub, RunKey
~q:: gosub, RunKey
~r:: gosub, RunKey
~s:: gosub, RunKey
~t:: gosub, RunKey
~u:: gosub, RunKey
~v:: gosub, RunKey
~w:: gosub, RunKey
~x:: gosub, RunKey
~y:: gosub, RunKey
~z:: gosub, RunKey
~1:: gosub, RunKey
~2:: gosub, RunKey
~3:: gosub, RunKey
~4:: gosub, RunKey
~5:: gosub, RunKey
~6:: gosub, RunKey
~7:: gosub, RunKey
~8:: gosub, RunKey
~9:: gosub, RunKey
~0:: gosub, RunKey
~NumpadIns:: gosub, RunKey
~Numpad1:: gosub, RunKey
~NumpadEnd:: gosub, RunKey
~Numpad2:: gosub, RunKey
~NumpadDown:: gosub, RunKey
~Numpad3:: gosub, RunKey
~NumpadPgDn:: gosub, RunKey
~Numpad4:: gosub, RunKey
~NumpadLeft:: gosub, RunKey
~Numpad5:: gosub, RunKey
~NumpadClear:: gosub, RunKey
~Numpad6:: gosub, RunKey
~NumpadRight:: gosub, RunKey
~Numpad7:: gosub, RunKey
~NumpadHome:: gosub, RunKey
~Numpad8:: gosub, RunKey
~NumpadUp:: gosub, RunKey
~Numpad9:: gosub, RunKey
~NumpadPgUp:: gosub, RunKey
~NumpadDot:: gosub, RunKey
~NumpadDel:: gosub, RunKey
~NumpadDiv:: gosub, RunKey
~NumpadMult:: gosub, RunKey
~NumpadAdd:: gosub, RunKey
~NumpadSub:: gosub, RunKey
~NumpadEnter:: gosub, RunKey
~F1:: gosub, RunKey
~F2:: gosub, RunKey
~F3:: gosub, RunKey
~F4:: gosub, RunKey
~F5:: gosub, RunKey
~F6:: gosub, RunKey
~F7:: gosub, RunKey
~F8:: gosub, RunKey
~F9:: gosub, RunKey
~F10:: gosub, RunKey
~F11:: gosub, RunKey
~F12:: gosub, RunKey
~F13:: gosub, RunKey
~F14:: gosub, RunKey
~F15:: gosub, RunKey
~F16:: gosub, RunKey
~F17:: gosub, RunKey
~F18:: gosub, RunKey
~F19:: gosub, RunKey
~F20:: gosub, RunKey
~F21:: gosub, RunKey
~F22:: gosub, RunKey
~F23:: gosub, RunKey
~F24:: gosub, RunKey
~Space:: gosub, RunKey
~Tab:: gosub, RunKey
~Enter:: gosub, RunKey
~Escape:: gosub, RunKey
~Backspace:: gosub, RunKey
~Delete:: gosub, RunKey
~Insert:: gosub, RunKey
~Home:: gosub, RunKey
~End:: gosub, RunKey
~PgUp:: gosub, RunKey
~PgDn:: gosub, RunKey
~Up:: gosub, RunKey
~Down:: gosub, RunKey
~Left:: gosub, RunKey
~Right:: gosub, RunKey
~ScrollLock:: gosub, RunKey
~CapsLock:: gosub, RunKey
~NumLock:: gosub, RunKey
~RShift:: gosub, RunKey
~LCtrl::	gosub, RunKey
~Pause:: gosub, RunKey
~LControl:: gosub, RunKey
~RControl:: gosub, RunKey
~LShift:: gosub, RunKey
~LAlt:: gosub, RunKey
~RAlt:: gosub, RunKey
~LWin:: gosub, RunKey
~RWin:: gosub, RunKey
~PrintScreen:: gosub, RunKey
~AppsKey:: gosub, RunKey
~Browser_Back:: gosub, RunKey
~Browser_Forward:: gosub, RunKey
~Browser_Refresh:: gosub, RunKey
~Browser_Stop:: gosub, RunKey
~Browser_Search:: gosub, RunKey
~Browser_Favorites:: gosub, RunKey
~Browser_Home:: gosub, RunKey
~Volume_Mute:: gosub, RunKey
~Volume_Down:: gosub, RunKey
~Volume_Up:: gosub, RunKey
~Media_Next:: gosub, RunKey
~Media_Prev:: gosub, RunKey
~Media_Stop:: gosub, RunKey
~Media_Play_Pause:: gosub, RunKey
~Launch_Mail:: gosub, RunKey
~Launch_Media:: gosub, RunKey
~Launch_App1:: gosub, RunKey
~Launch_App2:: gosub, RunKey
~XButton1:: gosub, RunKey
~XButton2:: gosub, RunKey



Runkey:
Esc::
if winc_presses > 0  

{
    winc_presses += 1
    Return
}
 
winc_presses = 1
SetTimer, TheKey, 400  
Return

TheKey:
SetTimer, TheKey, off
 if winc_presses = 2  
	{
	sendinput, {enter}
	}

winc_presses = 0
Return


Dan86
  • Members
  • 11 posts
  • Last active: Nov 10 2014 04:51 AM
  • Joined: 11 Oct 2014

Hi Scriptor,

 

Yes, that is kind of what I was looking for, however not even quickly in succession... even if I type the keys 5 seconds apart, for it to only hit return after a 2nd key has been entered.
I will test what you have given me, so thank you! I was just wondering if maybe there is an easier way to do it without needing to list them all int he menu.

Cheers!
 

 

here is a script that waits for any 2 keys to be pressed quickly in succession. For example, if you want it to work within your script, then when you press any 2 keys quickly (for example press 5 and then 9 quickly, or press A and then 4, or U and then F5), it will send enter. Doesn't matter what 2 keys have been pressed, so long as they are specified in the initial code. You can trim down that initial hotkey menu to just a few keys if you only want the code to work with just a few keys (1, 2, 3, 4, 5, 6, 7, 8, 9, 0 for example - just remove all other keys from the code). You can significantly trim this code down by removing any of the initial hotkeys that you might never use.  I don't know if this is what you want or how you could tie it into your code, but try it out:

#Persistent
#NoEnv


~a:: gosub, RunKey
~b:: gosub, RunKey
~c:: gosub, RunKey
~d:: gosub, RunKey
~e:: gosub, RunKey
~f:: gosub, RunKey
~g:: gosub, RunKey
~h:: gosub, RunKey
~i:: gosub, RunKey
~j:: gosub, RunKey
~k:: gosub, RunKey
~l:: gosub, RunKey
~m:: gosub, RunKey
~n:: gosub, RunKey
~o:: gosub, RunKey
~p:: gosub, RunKey
~q:: gosub, RunKey
~r:: gosub, RunKey
~s:: gosub, RunKey
~t:: gosub, RunKey
~u:: gosub, RunKey
~v:: gosub, RunKey
~w:: gosub, RunKey
~x:: gosub, RunKey
~y:: gosub, RunKey
~z:: gosub, RunKey
~1:: gosub, RunKey
~2:: gosub, RunKey
~3:: gosub, RunKey
~4:: gosub, RunKey
~5:: gosub, RunKey
~6:: gosub, RunKey
~7:: gosub, RunKey
~8:: gosub, RunKey
~9:: gosub, RunKey
~0:: gosub, RunKey
~NumpadIns:: gosub, RunKey
~Numpad1:: gosub, RunKey
~NumpadEnd:: gosub, RunKey
~Numpad2:: gosub, RunKey
~NumpadDown:: gosub, RunKey
~Numpad3:: gosub, RunKey
~NumpadPgDn:: gosub, RunKey
~Numpad4:: gosub, RunKey
~NumpadLeft:: gosub, RunKey
~Numpad5:: gosub, RunKey
~NumpadClear:: gosub, RunKey
~Numpad6:: gosub, RunKey
~NumpadRight:: gosub, RunKey
~Numpad7:: gosub, RunKey
~NumpadHome:: gosub, RunKey
~Numpad8:: gosub, RunKey
~NumpadUp:: gosub, RunKey
~Numpad9:: gosub, RunKey
~NumpadPgUp:: gosub, RunKey
~NumpadDot:: gosub, RunKey
~NumpadDel:: gosub, RunKey
~NumpadDiv:: gosub, RunKey
~NumpadMult:: gosub, RunKey
~NumpadAdd:: gosub, RunKey
~NumpadSub:: gosub, RunKey
~NumpadEnter:: gosub, RunKey
~F1:: gosub, RunKey
~F2:: gosub, RunKey
~F3:: gosub, RunKey
~F4:: gosub, RunKey
~F5:: gosub, RunKey
~F6:: gosub, RunKey
~F7:: gosub, RunKey
~F8:: gosub, RunKey
~F9:: gosub, RunKey
~F10:: gosub, RunKey
~F11:: gosub, RunKey
~F12:: gosub, RunKey
~F13:: gosub, RunKey
~F14:: gosub, RunKey
~F15:: gosub, RunKey
~F16:: gosub, RunKey
~F17:: gosub, RunKey
~F18:: gosub, RunKey
~F19:: gosub, RunKey
~F20:: gosub, RunKey
~F21:: gosub, RunKey
~F22:: gosub, RunKey
~F23:: gosub, RunKey
~F24:: gosub, RunKey
~Space:: gosub, RunKey
~Tab:: gosub, RunKey
~Enter:: gosub, RunKey
~Escape:: gosub, RunKey
~Backspace:: gosub, RunKey
~Delete:: gosub, RunKey
~Insert:: gosub, RunKey
~Home:: gosub, RunKey
~End:: gosub, RunKey
~PgUp:: gosub, RunKey
~PgDn:: gosub, RunKey
~Up:: gosub, RunKey
~Down:: gosub, RunKey
~Left:: gosub, RunKey
~Right:: gosub, RunKey
~ScrollLock:: gosub, RunKey
~CapsLock:: gosub, RunKey
~NumLock:: gosub, RunKey
~RShift:: gosub, RunKey
~LCtrl::	gosub, RunKey
~Pause:: gosub, RunKey
~LControl:: gosub, RunKey
~RControl:: gosub, RunKey
~LShift:: gosub, RunKey
~LAlt:: gosub, RunKey
~RAlt:: gosub, RunKey
~LWin:: gosub, RunKey
~RWin:: gosub, RunKey
~PrintScreen:: gosub, RunKey
~AppsKey:: gosub, RunKey
~Browser_Back:: gosub, RunKey
~Browser_Forward:: gosub, RunKey
~Browser_Refresh:: gosub, RunKey
~Browser_Stop:: gosub, RunKey
~Browser_Search:: gosub, RunKey
~Browser_Favorites:: gosub, RunKey
~Browser_Home:: gosub, RunKey
~Volume_Mute:: gosub, RunKey
~Volume_Down:: gosub, RunKey
~Volume_Up:: gosub, RunKey
~Media_Next:: gosub, RunKey
~Media_Prev:: gosub, RunKey
~Media_Stop:: gosub, RunKey
~Media_Play_Pause:: gosub, RunKey
~Launch_Mail:: gosub, RunKey
~Launch_Media:: gosub, RunKey
~Launch_App1:: gosub, RunKey
~Launch_App2:: gosub, RunKey
~XButton1:: gosub, RunKey
~XButton2:: gosub, RunKey



Runkey:
Esc::
if winc_presses > 0  

{
    winc_presses += 1
    Return
}
 
winc_presses = 1
SetTimer, TheKey, 400  
Return

TheKey:
SetTimer, TheKey, off
 if winc_presses = 2  
	{
	sendinput, {enter}
	}

winc_presses = 0
Return


scriptor
  • Members
  • 668 posts
  • Last active: Feb 15 2016 01:02 AM
  • Joined: 20 Jun 2013

you can remove a lot of the code by sticking to just letter and number keys. THis way whenever you type anything A-Z or 0-9 it will still work. At the top of the script, enter the window title (hopefully it'd an individual pop-up box where you enter your digits). The wait time is 400 (just under a half second) which means you need to double-tap the keys quickly, but if you increase that wait time up to say 5000, then you must press the keys within 5 seconds of eachother. You could increase it up to 1 minute or anything else if you wanted, but as I said hopefully the entry field is in its own mini pop-up window. But if you're entering the data in the main Excel window, then this won't work because no matter where else you type within Excel, it's going to hit enter any time you press 2 keys in succession no matter where on the screen you are entering it. Here's the stripped down code:

#Persistent
#NoEnv
#IfWinActive, ;put the window title here
~a:: gosub, RunKey
~b:: gosub, RunKey
~c:: gosub, RunKey
~d:: gosub, RunKey
~e:: gosub, RunKey
~f:: gosub, RunKey
~g:: gosub, RunKey
~h:: gosub, RunKey
~i:: gosub, RunKey
~j:: gosub, RunKey
~k:: gosub, RunKey
~l:: gosub, RunKey
~m:: gosub, RunKey
~n:: gosub, RunKey
~o:: gosub, RunKey
~p:: gosub, RunKey
~q:: gosub, RunKey
~r:: gosub, RunKey
~s:: gosub, RunKey
~t:: gosub, RunKey
~u:: gosub, RunKey
~v:: gosub, RunKey
~w:: gosub, RunKey
~x:: gosub, RunKey
~y:: gosub, RunKey
~z:: gosub, RunKey
~1:: gosub, RunKey
~2:: gosub, RunKey
~3:: gosub, RunKey
~4:: gosub, RunKey
~5:: gosub, RunKey
~6:: gosub, RunKey
~7:: gosub, RunKey
~8:: gosub, RunKey
~9:: gosub, RunKey
~0:: gosub, RunKey

Runkey:
if winc_presses > 0  
{
    winc_presses += 1
    Return
} 
winc_presses = 1
SetTimer, TheKey, 400 ;adjust the 400 to any other number to increase the wait time (such as 5000)
Return

TheKey:
SetTimer, TheKey, off
 if winc_presses = 2  
	{
	sendinput, {enter}
	}

winc_presses = 0
Return