You currently have Javascript disabled, to use some of the features (such as the login) you must enable it for this site
Getting pressed keys | Custom Buttons²

Getting pressed keys

Make Button Requests & Get Coding Assistance with Buttons You Are Working On

Postby j_ten_man on Thu Aug 07, 2008 4:34 pm

I was wondering if it was possible to determine which buttons were pressed when a user presses a button. Specifically I want to open a link in a new tab when a user is pressing ctrl and presses a button. I am thinking something along the lines of this.getAttribute('keypress') but that doesn't work. Any help would be great.
j_ten_man
Registered User
Registered User
 
Posts: 3
Joined: Thu Aug 07, 2008 4:27 pm

Postby jw25 on Thu Aug 07, 2008 7:08 pm

I'm not sure I understand what it is that you want in the new tab. If this code is used for the "cleftclick" mouse handler function a new tab will open when "Ctrl-left-click" is pressed.
Code: Select all
gBrowser.addTab('paste url here');
FF-3.0.3 | TB-2.0.0.18 | CB²-2.0.7.7 | XP Home
[ My Buttons ] [ Installed Firefox Buttons ] [ Thunderbird Buttons ]
User avatar
jw25
Admin
Admin
 
Posts: 463
Joined: Fri Jul 27, 2007 10:02 pm
Location: Lawrenceville, GA

Postby j_ten_man on Thu Aug 07, 2008 7:28 pm

I am confused as well. Where do I put that code? I create a new button and in the "Code" what do I put? If I just put that code then I don't have to press ctrl to open it in a new tab. Maybe there is a good walkthrough or tutorial about writing custom buttons. All I want is a real simple button that will open a link in the current tab if you click the button, and in a new tab if you are pressing ctrl when you press the button. I am not sure how to do this. Like I said, if there is a walkthrough or documentation on creating buttons, that would be useful because this forum is all over the place and it's tough to find how or what I can do in the button code.
j_ten_man
Registered User
Registered User
 
Posts: 3
Joined: Thu Aug 07, 2008 4:27 pm

Postby jw25 on Thu Aug 07, 2008 7:44 pm

If you check the extension options you will see the option to include the mouse handler functions in newly created buttons. To open a link in the current tab use the code:
Code: Select all
loadURI('paste url here');

The FAQ tab above will lead you to some tutorials.
Take a look at the code in this button to give you and idea of what I'm talking about.
Homepage/Bookmarks mgr/Homepage2
FF-3.0.3 | TB-2.0.0.18 | CB²-2.0.7.7 | XP Home
[ My Buttons ] [ Installed Firefox Buttons ] [ Thunderbird Buttons ]
User avatar
jw25
Admin
Admin
 
Posts: 463
Joined: Fri Jul 27, 2007 10:02 pm
Location: Lawrenceville, GA

Postby j_ten_man on Thu Aug 07, 2008 8:14 pm

Great. Thanks. I figured out that I need to put my code in the "Initialization" tab, and then that I needed this line:

this.setAttribute( 'onclick', 'gQuot( event, this )' ); // Calls the Golbal MouseClick handler gQuot

Here is the code I came up with:
Code: Select all
link = 'http://custombuttons2.com/forum';

this.leftclick   = function(evt){
   loadURI(link);
}

this.cleftclick   = function(evt){
   gBrowser.selectedTab =gBrowser.addTab(link);
}

this.setAttribute( 'onclick', 'gQuot( event, this )' );
j_ten_man
Registered User
Registered User
 
Posts: 3
Joined: Thu Aug 07, 2008 4:27 pm

Postby nicholas on Tue Aug 12, 2008 10:48 pm

if all you want to do is to open a link, then the Make a Bookmark button may be what you need:
http://www.custombuttons2.com/forum/but ... -t888.html
Custom Buttons²: v.2.0.7.7
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.4) Gecko/2008111318 Ubuntu/8.04 (hardy) Firefox/3.0.4
User avatar
nicholas
Admin
Admin
 
Posts: 1152
Joined: Thu Jun 14, 2007 6:30 pm
Location: Atlanta, GA USA


Return to Button Requests & Coding Assistance

Who is online

Users browsing this forum: • Registered: 0 and 0 guests