Showing posts with label Windows-OS. Show all posts
Showing posts with label Windows-OS. Show all posts

2021-02-19

Remap Capslock to Control in VirtualBox Linux guest on Windows host

Let's say you have Debian Linux guest OS in VirtualBox, running on a Windows 10 host.

Here's how to map capslock to control

If it was a Mac host, it'd be super easy: install and use Karabiner-Elements to remap capslock to control in the Mac host [3]. Now both host and guest Linux will have the remapping.  Done.

On Windows, it's not so easy.

You basically have to do the remapping in both Windows and Linux.  Follow the ideas here:

  1. Remap one key to another in Windows, like Capslock to Control 
  2. Remap one key to another in Linux, like Capslock to Control

Set shift key to break capslock for greater reliability

For greater reliability, you should also set shift key to break capslock.  So adding that to the Linux command for making capslock a control key, you'd get this command to run instead:

setxkbmap -option -option caps:ctrl_modifier -option shift:breaks_caps

The first blank "-option" clears any previously set.  Then the second option sets the capslock to control.  The third option makes shift key break capslock.

This is needed because sometimes switching between Windows host and Linux guest, the capslock gets locked down.  Now a quick tap on the shift key should break that lock.

What's wrong with remapping in Windows host only?

If you remap capslock to control in Windows host only, it'll actually sort of work in the Linux guest --- except in Linux, the capslock will now function as both capslock and control!

I did that for a while and didn't notice as I tested it inside Linux guest.  Capslock-T in Firefox still created new tabs!  Works!  But if you start typing, you'll notice things are in all caps until you tap capslock again, and vice versa.

What's wrong with remapping in Linux guest only?

If you remap capslock to control in Linux guest only, it'll actually work!  Except the capslock LED light will turn on/off with each click.  And if you switch back to Windows, capslock might have been engaged as you used capslock-as-control in Linux guest.

That's why you must do the remapping in both Windows host and Linux guest.  That way they stay in sync with each other, and the LED light won't turn on.

Capslock LED light in Linux

As I was troubleshooting the Linux guest only remapping, and noticed the capslock LED light would turn on/off, at first I thought the problem was in Linux.

And in case it is for your situation, here's how to fix or check.

xmodmap -e 'clear Lock' is suppose to clear the capslock LED from being turned on [1].  Try that, despite xmodmap being a deprecated system.

You can check if the LED is being turned on by Linux by running this command:

cat '/sys/class/leds/input5::capslock/brightness'

Turns out the LED property is represented as "just a file" on Linux you can open and read [2].

In my case, that command showed the LED was always off from Linux guest's point of view.  Turned out Windows host was controlling it.


Reference

[1] How to prevent the caps-lock toggle effect, without remapping or disabling it?

[2] Turn the Caps Lock LED on, while keep Caps Lock status is off

[3] Actually, I think Mac's System Preferences even have a built in setting for doing this remapping, so Karabiner might not even be needed for this single simple remapping.

2021-02-02

Enable 3 Finger Drag on Windows

3 Finger Drag (3FD) is not available on Windows, and not built-in on Linux

For Linux support, I'll write another post in the future.

On Windows, we can achieve something similar.  Let's call this:  3 Finger Tap to Drag Lock.

It's Dakshin's idea [1], refined further [2] and tweaked below.

What's 3FD anyway?

3 Finger Drag refers to a Mac accessibility feature.  When enabled, if you place three fingers on the Mac's trackpad or touchpad, then move those fingers in unison on the trackpad, the mouse pointer behave as if you left-clicked-and-are-dragging.

It's a better more ergonomic alternative to the tap-twice-and-drag method that's common on Macs, Windows, and Linux.

It's better because there's less finger tapping movement which can develop into "trigger finger" type repetitive strain injury.  If you drag things around a lot, tap-twice-and-drag plus another tap to deactivate dragging starts to add up to being a nuisance!

And at least for me, when dragging using the  tap-twice-and-drag gesture, I often have trouble continuing to drag mid-drag if I lift my hand away from the trackpad to reposition.  And ironically, I also have trouble disengaging the drag once I've reached the target of the drag motion too!

3 Finger Tap to Drag Lock (3FTD) on Windows

The gesture allows you to tap on the trackpad with 3 fingers, which will "lock" the left click down.  Then you can use 1 finger to move the cursor around, thus dragging what's clicked on!  A single tap again will disengage it.

You'll need to install AutoHotKey (AHK) as this is a script continuously running in the background to make it happen.

Installing the AHK Script

Make a text file and copy the script below into it, then save the text file with a .ahk file extension.  Double click the .ahk script file and AutoHotKey will run it to give you this 3FTD behaviour.

If you want the script to run every time you log in to Windows, you'll need to move the script or add a shortcut to it into the Windows startup folder.  See detailed instructions [3] for that.

ThreeFingerTapDragLock.ahk

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#SingleInstance force

drag_enabled := false

; Key combo for 4 finger tap:  #^+F24
#^+F22:: ; 3 finger tap
    if (drag_enabled) 
        Click, Up
    else
        Click, Down
    drag_enabled := !drag_enabled
return

#If drag_enabled
LButton::
    Click, Up
    drag_enabled := false
return
#If

Limitations of this script: games and VirtualBox

Chances are, this script won't work inside games.  Many games access the mouse and keyboard at a lower level than what AHK can effectively manipulate, or has anti-scripting functionality built-in.

AHK also doesn't play nice with VirtualBox since it's virtualizing the keyboard and mouse for the guest OS!

To avoid problems with VirtualBox, I tweaked the above script so it only works outside of it:

ThreeFingerTapDragLock_OutsideVBox.ahk

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#SingleInstance force

drag_enabled := false

#If !WinActive("ahk_exe VirtualBoxVM.exe")
; Key combo for 4 finger tap:  #^+F24
#^+F22:: ; 3 finger tap
    if (drag_enabled) 
        Click, Up
    else
        Click, Down
    drag_enabled := !drag_enabled
return


#If drag_enabled && !WinActive("ahk_exe VirtualBoxVM.exe")
LButton::
    Click, Up
    drag_enabled := false
return
#If

Note about the Key combo

My trackpad's 3 finger tap sends the key combo Win+Ctrl+Shift+F22.

And it's F24 instead of F22 if I 4 finger tap.

So the Key combo in the scripts above can be easily changed if you prefer a 4 finger instead of 3 finger gestures.

But also, if your laptop or vendor trackpad is different, you'll have to use AHK to find out the appropriate key combo to put in the script instead.


References

[1] Enable 3 Finger Gesture for click and drag on Windows and Linux

[2] AutoHotKey - Three finger dragging script causing minor issue, how to fix?

[3] How to Schedule AutoHotKey to Start Up with Windows

2021-01-27

How to disable Lenovo Fn-Tab Magnifier Hotkey

Lenovo makes some great laptops, like their ThinkPad T series.

But who's brilliant idea was it to "hard" wire the Fn-Tab key combo at a low level to activate the Windows Magnifier?

This annoying behaviour can't be remapped away with AutoHotKeys.

Lenovo's Vantage program calls them Hidden Keyboard Functions.  They're aware some people have a tendency to mistype Fn for Ctrl, so they offer a "Fn and Ctrl key swap" option instead.

Two ways to disable Fn-Tab Magnifier behaviour

(1) Disable permanently by changing the Magnify app's name

You can take file ownership of the Magnifier app, then change it's name from Magnify.exe to something else (e.g. Magnify.exe.bu as a backup).

That way, Fn-Tab can't find the Magnify app!

But Windows's own key combo won't find it either!  Congrats, you've disabled the Magnify hotkey permanently.

Detailed instructions can be found elsewhere [2] labelled as "method 2" (different than my # 2 below).

I don't like this method because I still want the Windows hotkey to bring up the Magnifier.

(2) Disable only the Fn-Tab hotkey

Inspired by a similar question from way way back [3], I found out the Fn-Tab hotkey will open any app who's path is entered into a specific Windows Registry entry!

Specifically, this Registry entry:

HKEY_LOCAL_MACHINE\SOFTWARE\Lenovo\ShortcutKey\AppLaunch\Ex_13\UIAccess

The key name "File" by default has the data value:

%SystemRoot%\system32\magnify.exe

Well if you change that to:

%SystemRoot%\system32\magnify.exe.bak

Then Fn-Tab won't find the magnify app and won't do anything!  In fact, you should be able to make Fn-Tab launch any app you want using this technique!

If you're trusting and lazy, and want an easy way to enable or disable the Lenovo Fn-Tab behaviour, save the following into text files and change the file extension to .reg so that you can double click the file to make the above registry edit for you:

EnableLenovoFnTabMagnify.reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Lenovo\ShortcutKey\AppLaunch\Ex_13\UIAccess]
"File"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
  00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,6d,00,\
  61,00,67,00,6e,00,69,00,66,00,79,00,2e,00,65,00,78,00,65,00,00,00
"Parameters"=""

DisableLenovoFnTabMagnify.reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Lenovo\ShortcutKey\AppLaunch\Ex_13\UIAccess]
"File"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
  00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,6d,00,\
  61,00,67,00,6e,00,69,00,66,00,79,00,2e,00,65,00,78,00,65,00,2e,00,62,00,61,\
  00,6b,00,00,00
"Parameters"=""



References

[1] Fn-TAB brings up Magnifier

[2] 3 Ways to Turn Off / Disable Magnifier in Windows 10

[3] Full of ThinkPad (Fn + SPACEBAR) screen magnifier

2021-01-20

Remap one key to another in Windows, like Capslock to Control

There's three options to consider for remapping keys on Windows.

(1) Manually edit the Windows Registry

You can directly edit the Windows registry to remap keys, for example to Map capslock to control.  You'll need to know the keyboard hex scan codes involved though.

(2) Edit the Windows Registry with SharpKeys

If you have many keys to remap, or don't want to manually mess with the registry, there's an App for that!  SharpKeys looks pretty good.  You can use it to remap the Right Alt to the Left Windows key for example.

(3) Don't edit the Registry but run a background app like PT or AHK

Some common remappings like Capslock to control can be easily done without editing the registry at all!  You can run an app that stays in the background, listening for the keys you want changed, then they'll inject the key you want for it to change to.

Microsoft's PowerToys has a module for that sort of usage, and it comes with other toys like advanced file name changer, etc.  The kind of key remapping allowed is extremely limited though.

Another option is AutoHotKey (AHK).  It'll give you extreme customization beyond remapping a single key to a single key.  It'll let you script keys and combos to do pretty much arbitrary things to the keyboard and mouse.

Don't run both PowerToys keyboard remapping module and AHK key remappings together as they may interfere with each other!

(NEW!)  Check out kinto if you're interested in mac-style hotkeys on Linux and Windows!

 

Remap Capslock to Control with AutoHotKey

Make a text file and copy the script below into it, then save the text file with a .ahk file extension.  Double click the .ahk script file and AutoHotKey will run it to give you this 3FTD behaviour.

If you want the script to run every time you log in to Windows, you'll need to move the script or add a shortcut to it into the Windows startup folder.  See detailed instructions for that.

CapslockAsControl.ahk

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#SingleInstance force

Capslock::Ctrl



Limitations to all methods

Some Windows hotkeys cannot be remapped!

Key combos like Windows key + L are dealt with by the Windows OS at a much lower level and treated specially.  Those cannot be remapped by PowerToys or AHK, at least not normally or usefully.

You could disable Win+L completely by disabling the Windows lock screen function [1].  But then your computer will never lock... ever.  Not when waking from sleep, not from the Control + Alt + Delete menu.  It's all or nothing.

Some apps don't allow / respect the remappings

Also apps that access the keyboard at a lower level, like some games and VirtualBox, don't play nice with AHK remappings.

Games access keyboards in a way that reduces latency to increase gaming responsiveness. And some games have anti-scripting functionality to discourage cheating.

VirtualBox is virtualizing your PC for another OS so a Windows background app messing with the keyboard of course won't play nice with VirtualBox.  And yes, Win+L will lock Windows even if you're inside a Linux guest in VirtualBox!

Vendor hotkeys can't be remapped

There are vendor specific keys and combos that your PC maker may have added via their keyboard drivers.  Like Lenovo's Fn+Tab starts the Windows magnifier key combo.  Press that while in a VirtualBox guest OS and it'll still run the magnifier!

Neither AHK nor PowerToys can remap the Fn+Tab combo either.  In fact, remapping the Fn key is usually tough if not impossible.  It's something handled specially by vendor's drivers on laptops to provide special functionality.

 

 

Compared to Macs

Scripting with AppleScript

Coming from the Mac world where AppleScript lets you implement customized and scripted automation of tasks, AutoHotKey (AHK) is similar in many ways.  Since AppleScript can be substituted with JavaScript, then the scripting language itself is better than AHK.

However, AppleScript doesn't provide hooks to customize or remap keys and key combos, so AHK does have this feature AppleScript doesn't.

On the flip side, Mac apps that make extensive use of Apple's Open Scripting Architecture allow AppleScripts to directly access certain data inside those apps for better integration.  Not every or many apps support advanced OSA usage, but it gives AppleScript an edge.

Remapping with Karabiner

As for providing key and combo remapping, I'm finding Karabiner-Elements on Macs to be better for that job than AHK.

Karabiner is more intuitive, purpose built for remapping keys, with many of the same AHK features for multi-key remapping.  It can also run scripts on key triggers like AHK, so Karabiner + AppleScript is roughly equivalent to AHK's functionality.

Less limitations

Macs have less limitations than Windows on the key remapping front too.  You'll have no problems using Karabiner-Elements to remap the "Apple key" (command key) vs the difficulties of remapping the Windows key (especially special combos like Win+L).

Key remappings with Karabiner on Macs are also respected by VirtualBox unlike remappings done via AHK on Windows.  To be fair, some AHK key remappings do work with VirtualBox, but I had trouble with modifier keys and special Windows hotkeys.


References

[1] How to disable Windows 10 Workstation Lock (Window + L) Functionality

2020-10-21

Quickly Open source code file location in OS's file browser from Netbeans

Want to open the file system browser to the location of a file or folder from Netbeans?

Easy, use the QuickOpener plugin.  Such a basic functionality requires a plugin, whereas it's built in in VS Code, but there it is.

Not the old QuickOpener that's been abandoned.

Use the new QuickOpener that's the fork of the old one (it's a friendly fork).

It works with Apache Netbeans, and can be found in the Netbeans plugin search area at least up to version 11.

For Netbeans version 12, you'll need to download the NBM plugin file from the online page of the new QuickOpener, then install it in Netbeans from the downloaded NBM file.  It worked for me in basic testing, so it should work fine.

2020-04-10

profile bash_profile bashrc on Ubuntu Linux, Macs, and Windows

I'm trying to get the same script to run and also set the $PATH for the login and non-login terminal shell on all 3 OSs: Windows, Mac, and Linux.

There's 3 parts to making it work:

Does the shell start in login or non-login mode?

  1. Mac's Terminal.app by default starts bash as a login shell.
  2. Ubuntu graphically logs in as a GUI shell (i.e. your desktop environment, gnome-session, etc.), so it's just not bash at all.  But if you then open a terminal in the desktop environment, your manually opened bash shell on Ubuntu may well start as a non-login (i.e. interactive) shell.
  3. Debian LXDE graphically logs in with bash and runs as a login shell by default.
  4. Windows Git Bash (MINGW64) seems to start as a login shell by default as well.

Which script runs on shell startup: .profile, .bash_profile, .bashrc?

  1. Gnome-session or whatever is your desktop environment (DE) is not bash, but the script that starts your DE is supposed to source ~/.profile but NOT ~/.bash_profile.  However, it's possible with Debian LXDE that it'll prefer ~/.bash_profile if it exists over the fallback that is ~/.profile.
  2. Bash as a login mode shell sources ~/.bash_profile and if that's missing then ~/.profile as a fallback.
  3. Bash as a non-login (interactive) shell sources ~/.bashrc and NOT those other two.

Where should scripts go to run on shell startup?

  1. So scripts that run only when your desktop environment or graphical shell starts goes into ~/.profile.
  2. Scripts that run only when you start bash in login mode --- e.g. started with bash -l, via the text console mode in Debian or Ubuntu e.g. via Ctrl + Alt + F2, when Mac's Terminal.app opens, or when Git's MINGW Bash opens on Windows --- goes into ~/.bash_profile.
  3. Scripts that run only when you start bash interactively (non-login mode) --- e.g. started by clicking the terminal icon having graphically logged in to Ubuntu's DE --- goes into ~/.bashrc.  This assumes you didn't configure your terminal emulator to run as a login shell!

Want the script to always run however shell starts up?

Suppose you want a bit of code to run when your shell starts.  It doesn't matter if it's a login, non-login (i.e. interactively started), graphical login from your desktop environment, on Macs, on Windows MINGW, etc.

In principle, I think ~/.bash_profile and ~/.profile both should source in ~/.bashrc as well, so scripts in ~/.bashrc should run whichever way you get your hands into a terminal UI in Ubuntu.  But Macs and Windows Git Bash doesn't have a proper .bash_profile to start.

Thus for Macs and Windows, favor ~/.bash_profile.

For Ubuntu Linux, favor ~/.bashrc.

A single method that works on all 3 platforms would be to put the code in ~/.bashrc, then make sure ~/.bash_profile sources in bashrc.



Bibliography

Why ~/.bash_profile is not getting sourced when opening a terminal?

DotFiles

2019-03-09

Maximally Cross Platform with React?

Once upon a time, going cross platform meant making an application that ran on both Macs and Windows, and maybe Linux/Unix if you're into that crowd.

Now everything is fragmented and compartmentalized.  Consider what "platforms" there are now for making apps:

  1. desktop web browsers --- i.e. Chrome, Firefox, Safari, vs Edge --- further divided by Macs, Windows, and Linux (at least for browsers that are cross platform, ha!)
     
  2. mobile web browsers --- i.e. iOS vs Android --- further divided by phone vs tablet display sizes
     
  3. Electron desktop apps --- i.e. Macs, Windows, vs Linux (built with web browser technology)
     
  4. native desktop apps --- i.e. Macs, Windows, vs Linux
     
  5. native mobile apps --- i.e. iOS vs Android --- further divided by phone vs tablet display sizes
Some of the above differences are a matter of building user interfaces sized for use on that display size, while other differences are a matter of framework (e.g. Cocoa vs Android SDK).

But at worse, that's still 26 different platforms to build for!  There are technologies that help bridge the divide, and one family of such tech is called React.

Here's a survey of some React based technologies and which platforms they work well for.


2016-11-27

Sharing TrueCrypt USB volume on 3 platforms: Mac, Windows, Linux

Edited 2017-04-02.

tl;dr: TrueCrypt exFAT volume on an exFAT disk. But creating such a volume is tricky!

Update for macOS Sierra: I upgraded to the latest macOS and TrueCrypt wouldn't work. After spending a little time on the problem, I gave up and went with VeraCrypt.  Remember to verify the VeraCrypt download though!

I've tried to find a solution to sharing a TrueCrypt encrypted volume on a USB memory stick between three platforms: Mac, Windows, Linux.  It's been tough to find something modern and reliable, as I tried HFS+, Ext2/Ext3/Ext4 on USB and in a TrueCrypt volume.

Modern means that it'll properly deal with big files (over 4 GB), and long international file names (over 8.3 UTF characters).

The best solution I've found so far is a TrueCrypt exFAT volume on an exFAT USB stick.  But creating such a volume is tricky!  Using the wrong software to do the formatting will destroy the TrueCrypt file.

It's modern, and okay but not great in reliability.  There's some caveats and things to watch out for though to make this work well for you.

Such a tri-platform TrueCrypt volume can be created in basically 2 steps:

2016-09-23

Ubuntu 16.04 guest + VirtualBox 5 + Windows: major version coordination bugs

Trying to run the latest Lubuntu (and I presume Ubuntu) 16.04 as the guest within a recent VirtualBox version (e.g. 5.0.22) on a Windows 7 host with anti-virus installed requires a certain amount of ... version coordination dancing, because of a series of unfortunate bugs.

The main problem is that the recent VirtualBox 5.x series has some major compatibility problems with Windows and/or the anti-virus installed with it.  Launching a VirtualBox image could result in a pretty scary error message like:
Error relaunching VirtualBox VM process: 5
Command line: ...............
(rc=-104)
And it's a "hard" error, blocking the VirtualBox image from even attempting to boot the guest OS.  Apparently it's something to do with "Hardened Security" [1].  There's some proposed workarounds but none of the proposed solutions worked for me.

Worse yet, after installation of VirtualBox 5.x (on a Windows 7 host) and successfully testing my Lubuntu guest image, my TrendMicro anti-virus updated overnight which created the above "Hardened Security" problem --- literally overnight!

The only reliable workaround is to downgrade VirtualBox back to the version 4.3.x series.  That's a workaround for the VirtualBox "Hardened Security" problem, but it creates new version compatibility problems between the guest OS and VirtualBox...  argh

But I found working workarounds.

2011-10-15

CamStudio - Free Screen Recording Software for Windows 7 64 bit

I hear Camtasia by TechSmith is great, but I want a lower cost solution for screen recording.  Some options include Jing, free and also from TechSmith, but that can only record 5 minutes and output to SWF files (not AVI - unless you pay for it).  Another option is CamStudio.

Strangely, CamStudio's main page lets you download the 2.0 version, which I gather is the last stable release version.

There are also two, more recent, beta versions: 2.5 and 2.6.  The 2.6 beta version didn't work for me - something to do with side-by-side configuration errors.

But the CamStudio 2.5 beta 1 version works for me in Windows 7 64 bit! Well, with some fiddling.  You'll need to download and install some files to make it work:

2011-01-18

Emacs Spell Check in Mac OS X

If you use emacs on a Linux or non-Mac Unix machine, it probably already has iSpell installed and configured so you could spell check in emacs (eg, use M-$).

In Mac OS X, you'll do well to use ASpell instead via CocoaASpell.

In Windows...I don't know.  There is an ASpell ported to Win32, but it is horribly out of date.

If you know a good emacs spell check solution for Windows, let me know in the comments below.  Thanks.

2011-01-15

Multi-threading Windows MFC Visual Studio C++ 2005

I was going to use Boost Threads, but then it turned out the MFC threads worked well enough for my purposes (I'm programming in Visual Studio 2005 in C++ using the MFC framework).

The documentation is a bit scattered, so here's what I found useful:
I didn't find the following useful, but what the heck, they looked useful enough:
If you are comfortable with the concept of threads, and you're just looking to find the language constructs to make them, here's the short of it:

If you want a thread that will make GUI elements to interact with the user, you'll want to check out Multithreading: Creating User-Interface Threads, but otherwise, it's quite simple.

Write a non-member function — it could be a regular function, or a static function of a class object, but it cannot be a "method"/instance function (sorry, I'm probably mixing up Java terminology here).

Then use AfxBeginThread to "spin" off a thread that wraps around the function you just wrote.  It'll execute your function on a thread.  There are options that allow you to make sure the thread object thus created does not auto-delete — you'll have to flag AfxBeginThread to not auto start the thread though, then use ResumeThread to start the thread after you've set m_bAutoDelete.

You don't want the thread object to auto-delete once the function it wraps around is done executing because you might want to keep tabs on the thread.  You might want to block execution until the thread(s) are done executing.  You can do this blocking with the WaitFor*Object(s) functions (documentation linked at top as well).

If the thread auto-deletes, the WaitFor* function can explode while trying to check if the thread is done executing.

You can throw off multiple threads wrapping around the same function.  If the function interacts with the outside world, you'll have to keep track of any synchronization issues yourself though.

2011-01-01

Emacs Fonts

I use emacs on Windows, Mac, and Ubuntu Linux, and I've been trying to keep my .emacs file in sync on all three platforms.  One thing that bothered me was the font.  It looked good on Ubuntu without my setting it, but when I go to Windows or Mac (in X11), the default font was just no good.

So to fix it, I went to Revisiting Programming Fonts to select the fonts I wanted: Consolas on Windows, and Inconsolata on Mac.  I installed those as you usually would in each respective operating system (emacs will use the system available fonts).

And then I put this in my .emacs file:

(if (string= (symbol-name system-type) "windows-nt")
    (set-default-font "-outline-Consolas-normal-normal-normal-mono-18-*-*-*-c-*-iso8859-1")
  (modify-frame-parameters nil '((wait-for-wm . nil))))

(if (string= (symbol-name system-type) "darwin")
    (set-default-font "-outline-Inconsolata-normal-normal-normal-mono-18-*-*-*-c-*-iso8859-1")
  (modify-frame-parameters nil '((wait-for-wm . nil))))

Now, I get Consolas font on Windows, and Inconsolata on Mac, and whatever was my default on Ubuntu that I didn't have to set manually!

If you don't know what fonts are available, it turns out you could find out in emacs by doing M-x set-face-font, then choose default, then hit the tab key twice to see the completion listing.  Scroll through the listing until you see the font name you want.  After noting down the name, just hit C-g several times to exit out of set-face-font so you could make the selection permanent by making the above adjustment in your .emacs file.

2010-12-05

Visual Studio C++ 2005 Side by Side DLL Configuration Errors

Previously, I had experienced the "modern" Windows 7 version of DLL Hell, ie, the Side by Side Configuration errors.  I had to reinstall Win7, so I had to experience this Side by Side DLL Hell all over again...  So here's a better and quick explanation of how to fix it:

Programs compiled in Visual Studio C++ may have a number of dynamic link library dependencies.  The dependency is specific down to the version of a library, so the Side by Side (SXS) feature allows Windows to manage having multiple versions of a library available for programs to link to.  These libraries are stored at C:\Windows\winsxs (so you can go have a look and see if you have a particular library needed).

Usually, programs so compiled have a manifest file of what dependencies is needed embedded in the binary of the compiled program.  You can ask Visual Studio to compile with the manifest file split out as a separate XML file by, in Visual Studio, going to Project > Properties > Manifest Tool > Input and Output, and setting the Embed Manifest option to No.  Then compile the program, and opening the XML file, your_program_name.exe.manifest, in any text editor.  It'll tell you which library you need, and which version.

For me, it turns out I needed two different versions of both the C/C++ standard libraries, and the MFC libraries.  After much searching, I found where you can download them from Microsoft:
"Normally," given that you have Visual Studio installed, you should have the necessary copy of those libraries available for redistribution to users without the necessary libraries in your Bootstrapper folder: C:\Program Files (x86)\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\vcredist_x.  But for whatever reason the copy I have there doesn't have the right version.

 Finally, there is some relevant discussion here.

2010-10-20

Getting Apple's Exposé feature on Windows 7

You need Switcher for Windows 7.  It can also be downloaded from CNET.

The computer power user, and especially a software developer, might have half a dozen windows open at times...per running application.  A few dozen tabs in Firefox, spread over a few windows.  Half a dozen Windows Explorer windows.  A Skype window.  A few Emacs windows.  Maybe a Pidgin window or two.  A few Visual Studio windows.  A Git GUI window or two.  You get the idea.

When things get messy, I want organization.  But when things just get over-whelming, I want a bird's eye view of everything.  And I mean everything.

Apple's Exposé is just ingenious for that.  It shows you all the windows you have open, laid out all for you to see all at once, on your giant 17'' LCD monitor.  That's the whole reason for getting a 17''+ size monitor, so you can see everything!

Ubuntu gives you the same feature, arguably with less polish, through Compiz's Scale Plugin.

What does Windows 7 have?  Nothing built-in.  You might think Aero Peek is the comparable feature, but nope, says another blogger, who I'll agree with.  How about Win7's Flip 3D feature?  If Flip 3D is an attempt to copy Exposé, it's a horrible attempt.  Why would anyone cascade the windows in 3D, showing me just the top of that stack of windows, using the entire screen?  When I have 30 windows open, I don't want to win-tab 15 times to get to the window I want!  Absolutely frustrating.

But there's Switcher, which is a fantastic clone of Exposé.  And it can also be downloaded from CNET.

I can finally be productive on Windows again.  Now if only there was a good multiple-copy-paste clipboard program for Windows...

2010-09-23

Emacs on Windows 7, and setting up ColorTheme

Wanting Emacs on Windows 7?  The install is easy.  There is nice but old instructions over at Installing Emacs on Windows 95/98/2K/NT/ME/XP/Vista/Windows 7.  Here's what I did (I used an administrator account.  YMMV).
  1. I wanted emacs in C:\Program Files (x86)\emacs, so I created that folder first
  2. Go here to get the latest emacs version. I got emacs-23.2-bin-i386.zip
  3. Unzip that file and dump its contents into C:\Program Files (x86)\emacs
  4. In Windows Explorer, open C:\Program Files (x86)\emacs\bin, then double click on runemacs.exe
  5. Yay! You have emacs running.  You may wish to add runemacs.exe to your Start menu (drag and drop it there)
Now I copied over from my Ubuntu Linux my .emacs and .emacs.d.  But where to place it?  If you follow Art Lee's instruction step 6, you can control where you want to place those files using the HOME Environment Variable (set in the Windows Control Panel).

On the other hand, why bother?  Especially if you are not running emacs as an administrator.  By default, the HOME will apparently be set as C:\Users\your_user_name\AppData\Roaming anyway, so copy .emacs and .emacs.d into that directory.

Unfortunately for me, coming from Ubuntu, I had ColorTheme installed via apt-get, so it wasn't contained in my .emacs.d.  I have to reinstall that now...

2010-09-20

Mapping caps lock to control key in Windows 7

Turns out it's really easy to map the caps lock key to the control key in Windows 7.  Instructions are everywhere, but these two were useful for me:
Despite the link title, the first link is best as it includes the registry changes needed saved into files you can download and import into the registry.

Oh, and the Registry Editor can be opened from the Start Menu's Search box as regedit.exe.

2010-09-05

Windows 7 loves to eat GRUB bootloader

Now I know why Grub is called Grub — Windows loves to eat it up every time it makes an update.  I've had to reinstall Grub about five times this week...

Two notes: my instructions from before works fine for my system.  But remember to unplug external USB drives other than the USB boot-up thumbdrive (or SD card in my case).

umm... and don't delete the Ubuntu linux boot-up drive once you've created it.  You'll need it whenever Windows updates itself and destroys Grub in the process.  Frustrating!

2010-08-31

Windows overwrote GRUB, and how to fix it

I don't use Windows much, and when I did, Windows 7 wanted to update a billion things (since I haven't used it for months).  Fine, but why does it have to brick my computer?  It overwrote GRUB on the MBR, so now it won't show the menu for picking which OS you want to start up in.  Now I can't boot up in Windows 7 or in Ubuntu 10.04.  How to fix it now?

The basic strategy is to boot up Ubuntu on an external disk, run some simple simple simple command line commands, and it's fixed.

The trouble is that it's my Dell Mini 10 netbook, and I don't have a DVD drive to boot from.  This means the first step is to build a bootable flash drive, and then fix GRUB.  Here's how: