Jump to content

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

Chromote - Enso styled Tabslock replacement.


  • Please log in to reply
No replies to this topic
octal
  • Members
  • 102 posts
  • Last active: Jul 24 2015 03:14 AM
  • Joined: 21 Feb 2011
So, its been a while since I've posted anything, mainly because I have so many uncompleted projects and I'm way too afraid to post anything...

Anyway.

Here's Chromote:

Posted Image

Which is exactly what the subject says.

Pretty much if you just tap Capslock, it opens or finds a chrome window. Then if you hold it down, it allows you to type in a url or search term.

I really enjoy the enso look, and I plan on turning this into a class so it can be easily implemented into other programs.

Download Zip
https://ahknet.autoh...te/Chromote.zip

#NoEnv
#winactivateforce
#singleinstance force
#include font.ahk
SendMode Input
SetWorkingDir %A_ScriptDir%
SetCapsLockState , off
AutoTrim, Off
Process, Priority, , High
SetTitleMatchMode, 2

onexit, cleanup

DllCall( "GDI32.DLL\AddFontResourceEx", Str,"GenR102.TTF",UInt,(FR_PRIVATE:=0x10), Int,0)

nHeight    :=  73
fnWeight   := 400 
fdwCharSet := 0x1
lpszFace := "Gentium (Humanized)"
ANTIALIASED_QUALITY := 0x4
NONANTIALIASED_QUALITY := 0x3


hFont1 := DllCall( "CreateFont", Int,nHeight, Int,0, Int,0, Int,0, UInt,fnWeight, Int,0
,Int,0, Int,0, UInt,fdwCharSet, Int,0, Int,0, Int,ANTIALIASED_QUALITY, Int,0, Str,lpszFace )


gosub init
gosub turnoff
gosub define

font:="s48 cWhite, Gentium (Humanized)"


ProgramName=Chromote
Version=0.1
Url=
IniFile=

/*
menu, tray, NoStandard
menu, tray, add, About, about
menu, tray, add, Settings, settings
menu, tray, add ; separator
menu, tray,add,Exit,cleanup
*/
return


$Capslock::
	hID=
	Typed=
	keywait, capslock, t.2
	If errorlevel
	{
		;WinSet, Region, 0-0 W20 H70 R10-10
		gosub turnon
		keywait, capslock
		gui, destroy
		gosub turnoff
	}

	
stringsplit, TLD, Typed, `.

if  (TLD0>1)
{
	tTLD:=TLD%TLD0%
	if (instr(TLDList, tTLD))
		url=%Typed%
}
else if Not Typed
{
	OpenChrome(1)
	return
}
else
{
	url:="http://www.google.com/#q="uriEncode(Typed)
	unurl=http://www.google.com/#q=%Typed%
}
	id:=lookforChrometab(1)
if id
	OpenChrome(0,url,1)
else
	OpenChrome(0,url)

	

Return

OpenChrome(t=0,text="", oldtab=0)
{
	if  (WinExist("ahk_class Chrome_WidgetWin_0")=0 or (t=0 and text!="" and oldtab=0))
	{
		EnvGet, USERPROFILE, USERPROFILE
		if text
			cmd=`"%text%`"
		
		Run "%USERPROFILE%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe" %cmd%
		return
	}
	id=nothing
	test:=lookforChrometab(0, id)
	WinActivate, ahk_id %id% ;notice i changed this part
	WinSet, Top
	if t
	{
		winwait,  ahk_id %id%
		ControlFocus, Chrome_AutocompleteEditView1, ahk_id %id%
		sendinput, ^t
	}
	if text
	{
		winwait,  ahk_id %id%
		ControlFocus, Chrome_AutocompleteEditView1, ahk_id %id%
		sendinput, {Raw} %text%
		sendinput  {enter}
	}
}


lookforChrometab(newtab=0, byref ID="")
{
	if newtab
	{
		WinGet, id, list,,, Program Manager
		Loop, %id%
		{
			this_id := id%A_Index%	
			WinGetTitle, tTitle , ahk_id %this_id%
			if (tTitle="New Tab - Google Chrome")
			{
				if id
				d:=this_id
				return 1
			}
		}
	}
	if id
		ID:=WinExist("Google Chrome")

	return 0
}
+Capslock::Capslock


iniread:
	;iniread, movemax, %inifile%,Settings,movemax
	;iniread, wininfo, %inifile%,Settings,wininfo
return

iniwrite:
	;IniWrite, 1, %inifile%, Settings, movemax
	;IniWrite, 1, %inifile%, Settings, wininfo
return

settings:
	gui 66: default
	gui,add,button,gsave,Save
	gui,show,,Settings
	gui 1: default
return

save:
	gui 66: default
	gui,submit
	gui,destroy
	gui 1: default
	gosub iniwrite
return

about:
	msgbox %programname% v%version%`nBy: Jason Stallings
return

cleanup:
DllCall( "GDI32.DLL\RemoveFontResourceEx",Str,"GenR102.TTF",UInt,(FR_PRIVATE:=0x10),Int,0)
exitapp
	
	
makegui:
Gui, +LastFound +AlwaysOnTop -Caption +toolwindow
Gui, Color, black
Gui,Font, s48 cWhite, Gentium (Humanized)

gui, add, text,w%a_screenwidth% x15 y15 hwndText,

SendMessage, 0x30, hFont1, 1,, ahk_id %Text%
WinSet, Transparent, 220
gui,show, disabled NA h98 x-10 y48 w%a_screenwidth%
WinSet, Region, 0-0 W20 H98 R10-10
		hID:=winexist()


return


alpha_label:
if (hid="" and typed="")
	gosub makegui
	stringleft, check, A_ThisHotkey, 1
	If A_ThisHotkey=BackSpace
	{
		stringtrimright, typed, typed, 1
	}
	Else If A_ThisHotkey=Space
	{
		typed=%typed%%A_SPACE%
	}
	Else If  (check="*")
	{
		stringtrimleft, real, A_ThisHotkey, 1
		typed=%typed%%real%
	}
	Else
	{
		typed=%typed%%A_ThisHotkey%
	}
	size:=Font_DrawText(Typed,	typed,  "s48 cWhite, Gentium (Humanized)", "CALCRECT")
	StringSplit, size, size, .
	FontWidth := size1,
	FontWidth+=10
	guisize:=FontWidth+18
	FontHeight := size2
	if typed=
	{
		hID=
		gui, destroy
		return
	}
	Guicontrol,, Static1, %Typed%
	WinSet, Region, 0-0 W%guisize% H98 R15-15, ahk_id %hID%
return


init:
turnon:
turnoff:

	If (A_ThisLabel="turnoff")
		mod=off
	Else If (A_ThisLabel="turnon")
		mod=on
	Else
		mod=alpha_label

		
	total:=94
	Loop %total%
	{
		
		thisloop:=total-A_INDEX
		check:=thisloop+32

		if (check<48 or (check<=48 and check>=55) or (check>=64 and check<=90))
		{
			thishotkey:=Chr(thisloop+0x20)
			if instr("'", thishotkey)
				thishotkey=%thishotkey%
			else
				thishotkey=*%thishotkey%
			Hotkey, %thishotkey% ,%mod%
		}
		else
		{
			thishotkey:=Chr(thisloop+0x20)
			thishotkey=%thishotkey%
			Hotkey, %thishotkey% ,%mod%
		}
	
	}
	
	

	Hotkey, BackSpace ,%mod%
	Hotkey, Space ,%mod%

;listhotkeys
return

define:
TLDList=
(
aero	
asia	
biz	
cat	
com	
coop	
edu	
gov	
info	
int	
jobs	
mil	
mobi	
museum	
name	
net	
org	
pro	
tel	
travel	
)
return




uriEncode(str)
{ ; v 0.3 / (w) 24.06.2008 by derRaphael / zLib-Style release
   b_Format := A_FormatInteger
   data := ""
   SetFormat,Integer,H
   Loop,Parse,str
      if ((Asc(A_LoopField)>0x7f) || (Asc(A_LoopField)<0x30) || (asc(A_LoopField)=0x3d))
         data .= "%" . ((StrLen(c:=SubStr(ASC(A_LoopField),3))<2) ? "0" . c : c)
      Else
         data .= A_LoopField
   SetFormat,Integer,%b_format%
   return data
}


I know there's a lot of better ways to do stuff. So teach me! :D

Edit:
Know bugs:
If you hit backspace with capslock down and nothing entered, it flickers.
If you go past the limit of the screen, it doesn't do anything. (should get smaller)
Um, if you try to type "1234" really quick it skips 2. Because it won't trigger 2 while 1 is held down, but 3 and 4 trigger fine...