Press F1, F2, F3, F4 and disable all keys but up, down, enter & escape

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
RetroBorg
Posts: 4
Joined: 22 Oct 2017, 18:04

Press F1, F2, F3, F4 and disable all keys but up, down, enter & escape

22 Oct 2017, 18:36

I was hoping someone could help me on a script.

I would like a script that when F1, F2, F3 or F4 are pressed, all keys except UP, DOWN, ENTER and ESCAPE are disabled.

During this time when only these keys are active, if the ENTER key is pressed, it sends {ENTER} followed by the same Function key previously selected and continues to only have UP, DOWN, ENTER and ESCAPE keys active.

If ESCAPE is pressed then sends {ESC} and everything returns to normal.

I hope this make sense, any help would be greatly appreciated.

Cheers.
User avatar
theimmersion
Posts: 181
Joined: 09 Jul 2016, 08:34
Location: Serbia

Re: Press F1, F2, F3, F4 and disable all keys but up, down, enter & escape

22 Oct 2017, 18:59

What an odd combo, may i ask what the specific purpose of such script is? Very curious and why send enter than F??.
Try this:

Code: Select all

#NoEnv ; Avoids checking empty variables to see if they are environment variables
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance Force

QUIT_HOTKEY=Esc
F1_HOTKEY=F1
F2_HOTKEY=F2
F3_HOTKEY=F3
F4_HOTKEY=F4
ENTER_HOTKEY=Enter
UP_HOTKEY=Up
DOWN_HOTKEY=Down

#HotkeyInterval 400 ;2000
#MaxHotkeysPerInterval 500

Menu,Tray,Click,1
Menu,Tray,DeleteAll
Menu,Tray,NoStandard
Menu,Tray,Add,Exit,ForceExit
Menu,Tray,Default,Exit

Hotkey,%QUIT_HOTKEY%,ExitSub
Hotkey,%F1_HOTKEY%,F1Sub
Hotkey,%F2_HOTKEY%,F2Sub
Hotkey,%F3_HOTKEY%,F3Sub
Hotkey,%F4_HOTKEY%,F4Sub
Hotkey,%ENTER_HOTKEY%,EnterSub
Hotkey,%UP_HOTKEY%,UpSub
Hotkey,%DOWN_HOTKEY%,DownSub

/*
BlockKeyboardInputs("On")
BlockMouseClicks("On")
BlockInput MouseMove
*/
return

ExitSub:
	Send, {Esc}
	Reload
	;ExitApp
Return

F1Sub:
	if (LAST_HOTKEY = "")
	{
		LAST_HOTKEY=F1
		BlockKeyboardInputs("On")
	}
Return
F2Sub:
	if (LAST_HOTKEY = "")
	{
		LAST_HOTKEY=F2
		BlockKeyboardInputs("On")
	}
Return
F3Sub:
	if (LAST_HOTKEY = "")
	{
		LAST_HOTKEY=F3
		BlockKeyboardInputs("On")
	}
Return
F4Sub:
	if (LAST_HOTKEY = "")
	{
		LAST_HOTKEY=F4
		BlockKeyboardInputs("On")
	}
Return

EnterSub:
	Send, {Enter}
	Sleep, 100
	Send, {%LAST_HOTKEY%}
Return
UpSub:
	Send, {Up}
Return
DownSub:
	Send, {Down}
Return

BlockKeyboardInputs(state = "On")
{
	static keys
	keys=Space,Enter,Tab,Esc,BackSpace,Del,Ins,Home,End,PgDn,PgUp,Up,Down,Left,Right,CtrlBreak,ScrollLock,PrintScreen,CapsLock
,Pause,AppsKey,LWin,LWin,NumLock,Numpad0,Numpad1,Numpad2,Numpad3,Numpad4,Numpad5,Numpad6,Numpad7,Numpad8,Numpad9,NumpadDot
,NumpadDiv,NumpadMult,NumpadAdd,NumpadSub,NumpadEnter,NumpadIns,NumpadEnd,NumpadDown,NumpadPgDn,NumpadLeft,NumpadClear
,NumpadRight,NumpadHome,NumpadUp,NumpadPgUp,NumpadDel,Media_Next,Media_Play_Pause,Media_Prev,Media_Stop,Volume_Down,Volume_Up
,Volume_Mute,Browser_Back,Browser_Favorites,Browser_Home,Browser_Refresh,Browser_Search,Browser_Stop,Launch_App1,Launch_App2
,Launch_Mail,Launch_Media,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,F14,F15,F16,F17,F18,F19,F20,F21,F22
,1,2,3,4,5,6,7,8,9,0,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
,²,&,é,",',(,-,è,_,ç,à,),=,$,£,ù,*,~,#,{,[,|,``,\,^,@,],},;,:,!,?,.,/,§,<,>,vkBC
	Loop,Parse,keys, `,
		Hotkey, *%A_LoopField%, KeyboardDummyLabel, %state% UseErrorLevel
	Return
KeyboardDummyLabel:
Return
}

; ******************************************************************************
BlockMouseClicks(state = "On")
{
	static keys="RButton,MButton,WheelUp,WheelDown"
	Loop,Parse,keys, `,
		Hotkey, *%A_LoopField%, MouseDummyLabel, %state% UseErrorLevel
	Return
MouseDummyLabel:
Return
}

ForceExit:
	ExitApp
User avatar
theimmersion
Posts: 181
Joined: 09 Jul 2016, 08:34
Location: Serbia

Re: Press F1, F2, F3, F4 and disable all keys but up, down, enter & escape

22 Oct 2017, 19:10

Btw, i dont know if you literally mean send enter than the last function key pressed or if you press enter it would send the function key instead. Same with Esc. It sends that key literally through and at same time unlocks the keyboard.
Also, if you wish to be able to change last function key pressed while still having the keyboard locked, just change function key subs with according number changes.

Like this F1 key sub:

Code: Select all

F1Sub:
	if (LAST_HOTKEY = "")
	{
		LAST_HOTKEY=F1
		BlockKeyboardInputs("On")
	}
	else
	{
		LAST_HOTKEY=F1
	}
Return
etc...
RetroBorg
Posts: 4
Joined: 22 Oct 2017, 18:04

Re: Press F1, F2, F3, F4 and disable all keys but up, down, enter & escape

22 Oct 2017, 19:28

Thanks heaps for your reply theimmersion, wow you are quick!

This is for a jukebox project that runs software called SK Jukebox.

Image

Pressing F1 opens the top left corner album to full screen, you then can navigate the songs by pressing up and down and to select the highlighted song by pressing enter.

Unfortunately there is problem with the software where once you select a song the highlighted bit that moves up and down to select a song disappears and you need to push F1 again to make it reappear.

F2 opens bottom left album to full screen and so on for F3 and F4.

Escape button closes album full screen.

Unfortunately your script doesn't seem to work for me.

I probable have explained it poorly.

Pressing F1, F2, F3 & F4, should send {F1} etc initially which doesn't seem to be happening.

I really appreciate your help.

Cheers.
User avatar
theimmersion
Posts: 181
Joined: 09 Jul 2016, 08:34
Location: Serbia

Re: Press F1, F2, F3, F4 and disable all keys but up, down, enter & escape

22 Oct 2017, 19:38

oh. well no prob, simple edit.
Add "Send, {F?}" to all the F?Sub.
Like this:

Code: Select all

F1Sub:
	if (LAST_HOTKEY = "")
	{
		Send, {F1}
		LAST_HOTKEY=F1
		BlockKeyboardInputs("On")
	}
Return
This should work.
Its really not that hard. just take a good look, use logic and try experimenting and you can modify stuff for yourself when you have the base code. ^^

Now with this edit, it will first send the F? key, than designate that key as last pressed and than lock the keyboard.

Also, in the F?Sub "else" block i mentioned earlier, you can either make it set to last key pressed or you can as well make the key send itself instead.
Since i dont have that program, cant test it myself and would be much easier but hope this will fix it.
What i mean by else is that if you press F1 but than instead change your mind and press F2, you can bring the menu up without needing to press enter since the F keys are not free because as far as i understood, only free keys is esc, up, down, enter. So with this, you will be able to activate F keys freely if need be.

Code: Select all

F1Sub:
	if (LAST_HOTKEY = "")
	{
		Send, {F1}
		LAST_HOTKEY=F1
		BlockKeyboardInputs("On")
	}
	else
	{
		Send, {F1}
		LAST_HOTKEY=F1
	}
Return
RetroBorg
Posts: 4
Joined: 22 Oct 2017, 18:04

Re: Press F1, F2, F3, F4 and disable all keys but up, down, enter & escape

23 Oct 2017, 06:31

Code: Select all

F1Sub:
	if (LAST_HOTKEY = "")
	{
		Send, {F1}
		LAST_HOTKEY=F1
		BlockKeyboardInputs("On")
	}
	else
	{
		Send, {F1}
		LAST_HOTKEY=F1
	}
This works perfectly except I need to push the functions keys twice each time to go in to full album mode.
RetroBorg
Posts: 4
Joined: 22 Oct 2017, 18:04

Re: Press F1, F2, F3, F4 and disable all keys but up, down, enter & escape

24 Oct 2017, 17:11

I've played around with it a bit but can't get it to enter full screen mode with just one press of one of the function keys.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo and 211 guests