Sunteți pe pagina 1din 4

Alt key Handler

A routine to extend Writer so that the Alt key can be used for shortcuts

How it works
When a keyHandler routine is set-up for a Writer document then any key that gets pressed can be analysed by the keyHandler. The keyHandler routine in the macros associated with this document check if the Alt key was pressed, if it wasn't pressed then the keyHandler exits allowing other routines to process the key. If the Alt key was pressed then it checks against an array to determine what action to take. Included in these macros is a dialog to assist with managing the array, it allows you to assign styles, text, commands, and macros (that are in the global BASIC libraries soffice). If there is no assignment for the key press then the keypress is passed on to any other key handlers.

Testing
This macro requires installing before you can test it.. See Installing on page 3 below, especially if you are upgrading this macro as you could lose your current Alt+Key assignments. Having installed the macro try the Alt+key assignments. E.g. Alt+1 should apply paragraph style Heading 1, Alt+M should insert an em dash, Alt+R should reset attributes (i.e same as Right click Default or Format > Default) and Alt+Control+T should give a hanging indent, and Alt+A should run the Alt key assignment macro.

The Alt key assignment dialog


Shift and Control check boxes
Checking these boxes determines what modifier key combination is to be assigned. The Alt key checkbox is disabled and is only there to remind you that all key combinations for this macro are using Alt.

Left Listbox
This list box shows the current assignments for the keys. The first character is the actual key, currently this macro only handles 0-9 and A-Z. Then there is a space and a single character which describes what sort of action to take, as per the following table: Letter P C F p n T c M Action Apply Paragraph style Apply Character style Apply Frame style Apply page style Apply numbering style Insert the following text Run the following dispatch command Run the following global macro

And lastly either the name of the style, the text to be inserted, the command to be dispatched or the macro to be run. Select an item in this listbox to assign or remove an action to the keypress. When selecting key presses without other modifiers remember that some of those key presses activate the menu e.g. Alt+F for the file menu so you probably don't want to use them.

Top right drop down


This drop down lists the different types of actions that can be assigned. Choose the desired type of action and the controls below it will change to suit.

Styles
Second drop down

This contains the different types of styles that can be applied in Writer: Paragraph, character, and Numbering. Selecting one of these style types will change the listbox below to display the corresponding styles for the current document.
Style listbox

Click on a style name in this listbox so that when you click the Assign button that this style is associated with the currently selected keypress.

Text
Type text into the text field. You may want to use the Insert Special dialog by pressing Control+Shift+S. Note that the Insert Special dialog is more limited when working in a textbox than it is when working in a Writer document in that you cannot change the font. Therefore you may want to have inserted the special character into your Writer document and copied it so that you can simply paste it in using Control+V. Then click the Assign button.

Commands
The commands listbox displays a list of Writer dispatch commands. Select a command and click the Assign button. The list of commands are those commands listed in slots.sxc, a file documenting the dispatch slots for OOo available from http://api.openoffice.org/files/documents/22/1344/slots.sxc, for Writer without any additional parameters.

Macros
Select the global library, then module and lastly macro. Click the Assign button.

Assign button
Having selected the what addition modifiers (Control and/or Shift) if any, what key press and what action, click the assign button to actually make the assignment.

Remove button
Clicking this button will remove the action from the currently selected keypress.

OK button
Click this button to actually save the changes.

Doc button
This button creates a new document with a table showing all of the Aly key assignments. If you have made changes it will ask if you wish to save the changes and close the dialog.

Cancel button
Click this button to ignore any assignments that you have just made and close the dialog. If you have made changes it will double check with you.

Installing
Adding the library
This is so that the macro will be available for use when required 1. Tools > Macros > Macro... > Organizer > Libraries 2. Ensure that sOffice is selected for Application/Document 3. Click Append... 4. Navigate to where this file is stored and select it, click Open 5. If you already have a library called AltKeySettingsDyn do not check it as you will lose all your current Alt+Key settings. If you are updating AltKeyHandler and don't have AltKeySettingsDyn then you have a very early version and don't want to lose your key assignments then you will need to install AltKeySettingsDyn and use copy and replace from the your module LoadSettings in AltKeyHandler of the key assignments between the sub and end sub (do not include the line starting with sub). Before recommencing at step 1. 6. Uncheck Standard but ensure AltKeyHandler is checked 7. If updating from an old version check Replace existing libraries 8. Ok > Close > Close

Setting up the alt key handler so that it works on all Writer documents
1. Tools > Configure... > Events 2. Make sure that OpenOffice.org is selected top right 3. In the Macros list box: Click the + next to OpenOffice.org BASIC Macros, the plus next to AltKeyHandler, then click AltKeyHandler. 4. In the listbox now labelled AltKeyHandler select SetupAltKeyHandler 5. In the top listbox click on Create Document > Assign and then Open Document Assign 6. Click OK

Indents
I have included routines for creating indents in a similar way to what Word and Word Perfect do.

Try Indent demos


When testing macros it is always a good idea to only have the current test document open. There are three small macros, to test them select a longish paragraph and click the buttons:

IncreaseHangingIndent: Works like Control + T in Word IncreaseHangingIndent DecreaseHangingIndent: Works like Control + Shift + T in Word DecreaseHangingIndent WordPerfectIndent: Works like Indent in Word Perfect WordPerfectIndent

Notes about indent use


For each of these macros if there is no tab stops defined then the default tab stops are used. To change the default tab stop use: Tools > Options > Text Documents > General and in the middle of the dialog is an option for changing the default tab stops. The IncreaseHangingIndent changes the selected paragraph's left margin to be at the first tab stop and the first line to be at the paragraph's original first line starting point (using a negative amount). Writer's tab stops are based on the left margin for the paragraph, where as Word's are based on the left margin for the page. In Word pressing Control + T with set tab stops will adjust the hanging indent to each of those tab stops in turn, where as this macro adjusts to the first tab stop which gets automatically adjusted with each run of the macro. This macro works on the current selection including multiple selections. Note that for each selection in the same paragraph the indenting will occur, I.e. Two selections in the same paragraph and the paragraph will be indented twice. The DecreaseHangingIndent is the reverse of IncreaseHangingIndent. WordPerfectIndent works like Indent in Wordperfect (it is about 10 years since I used WordPerfect so my memory maybe faulty), in that as you are typing you want to have a hanging indent after your current text. E.g. At the start of a paragraph you type some short heading like a date, then run this macro and keep typing. What the macro does is insert a tab stop and changes to paragraph's left margin to begin at this point and the first line for the paragraph to be at the original location of the first line.

Copyright
Copyright 2004 Ian Laurenson Anyone may run the code associated with this document. If you wish to modify or distribute this document and or its code, then you are granted a license to do so under the terms of the Gnu Lesser General Public License. See: http://www.gnu.org/licenses/lgpl.html.

Author contact
Send comments, bug fixes, change requests etc to hillview@paradise.net.nz

S-ar putea să vă placă și