Questions tagged [hook]

A hook refers to replacing or extending a system or application's default behavior with a custom behavior for a specific event. For keyboard hooks prefer the tag [keyhook]. For git related hooking use the tag [githooks] alone. For hooking web services use the tag [webhooks] instead. For React hooks use tag[react-hooks].

What is it?

A hook refers to replacing or extending the default behavior with a custom behavior for specific events. The events may be operating system events, but also application events that are meant to be extended with hooks.

The hook may fully replace the default behavior. It may also just extend the default behavior for example by adding a listening or monitoring activity without changing the default behavior, or add an extra effect on the top of it.

Hooking and programming techniques

"Hook" is commonly used to describe replacing a function pointer in an existing data structure with a new function pointer that points to new code. This new code can extend the default behavior by calling the old function pointer before or after the new code executes, or the new code can replace / disable the existing behavior by not calling the old pointer.

Hooking is similar in concept to OOP inheritance, but is usually more dynamic (determined at runtime) than OOP inheritance.

Essentially it's a place in code that allows you to tap in to a module to either provide different behavior or to react when something happens. Hooks often (but not always) use callback functions. For example, you might hook an event system using hookEvent(Events.STARTUP, myCallbackFunction). You are passing a function pointer to the hookEvent function, so it knows what function to call when the event occurs.

How does it work?

Typically hooks are inserted while software is already running, but hooking is a tactic that can also be employed prior to the application being started. There are two techniques to achieve this:

  • Physical modification
  • Runtime modification

Related tags and disambiguation

  • For the hooks related to keyboard events, prefer the tag
  • For the hooking git events, you must use the tag preferably without the
  • For hooking web services with web service callbacks prefer the tag
  • For React hooks, prefer the tag

More Information

5710 questions
68
votes
6 answers

How can I prevent Subversion commits without comments?

Does anybody know how to prevent commits to a Subversion code repository when there is no commit comment entered?
user234518
59
votes
5 answers

How to remove remote git hooks?

I have pre-push hook implemented with Husky. Now I wanna remove it. Problem is that after yarn remove husky git hooks are still there inside .git/hooks. Because of that I get this error every time I want to commit or switch branch or commit, thus…
Nikola Mitic
  • 1,298
  • 3
  • 11
  • 23
52
votes
16 answers

How do I make Subversion (SVN) send email on checkins?

I've always found checkin (commit) mails to be very useful for keeping track of what work other people are doing in the codebase / repository. How do I set up SVN to email a distribution list on each commit? I'm running clients on Windows and the…
Joe Ludwig
  • 6,756
  • 7
  • 30
  • 29
52
votes
6 answers

How to get the word under the cursor in Windows?

I want to create a application which gets the word under the cursor (not only for text fields), but I can't find how to do that. Using OCR is pretty hard. The only thing I've seen working is the Deskperience components. They support a 'native' way,…
blez
  • 4,939
  • 5
  • 50
  • 82
52
votes
5 answers

What is the difference between hook and callback?

By reading some text, especially the iOS document about delegate, all the protocol method are called hook that the custom delegate object need to implement. But some other books, name these hook as callback, what is the difference between them? Are…
coanor
  • 3,746
  • 4
  • 50
  • 67
49
votes
10 answers

How to require commit messages in VisualSVN server?

We've got VisualSVN Server set up as our Subversion server on Windows, and we use Ankhsvn + TortoiseSVN as clients on our workstations. How can you configure the server to require commit messages to be non-empty?
Ben Collins
  • 20,538
  • 18
  • 127
  • 187
46
votes
2 answers

Can you change a file content during git commit?

One of the things I keep in my open novel in GitHub is a list of words I would like to set automatically the first line, which is the number of words in the dictionary. My first option is to write a pre-commit hook that reads the file, counts the…
jjmerelo
  • 22,578
  • 8
  • 40
  • 86
44
votes
3 answers

How to specify which SSH key to use within git for git push in order to have gitorious as a mirror?

I have a project hosted on git.debian.org (alioth) and I'd like to configure a post-receive hook to update a mirror of the repository on http://gitorious.org I suppose I'll have to use git push --mirror gitorious Now, I'll need to have Alioth…
Mildred
  • 3,887
  • 4
  • 36
  • 44
44
votes
4 answers

Monitoring application calls to DLL

In short: I want to monitor selected calls from an application to a DLL. We have an old VB6 application for which we lost the source code (the company wasn't using source control back then..). This application uses a 3rd party DLL. I want to use…
kshahar
  • 10,423
  • 9
  • 49
  • 73
43
votes
7 answers

Get commit message in Git hook

I would like to check the commit message before Git commit. I use a pre-commit hook to do that, but I couldn't find the way to get the commit message in the .git/pre-commit script. How could I get it?
fish potato
  • 5,319
  • 6
  • 27
  • 32
42
votes
5 answers

Git pre-commit hooks only for a specific subfolder?

I currently have a single repo with two projects, each in their own subfolder: one in C# and one in Javascript. I want to have a pre-commit hook that will run jshint but only if any of the staged files are in the Javascript folder If the staged…
somecoolguy
  • 431
  • 1
  • 4
  • 3
42
votes
5 answers

C# How to find if an event is hooked up

I want to be able to find out if an event is hooked up or not. I've looked around, but I've only found solutions that involved modifying the internals of the object that contains the event. I don't want to do this. Here is some test code that I…
Nick
  • 2,913
  • 12
  • 40
  • 52
40
votes
22 answers

Share common / useful SVN pre-commit hooks

What are some common and/or useful pre-commit hooks for SVN?
powtac
  • 40,542
  • 28
  • 115
  • 170
40
votes
2 answers

git-clone and post-checkout hook

According to the manual, the post-checkout hook is run after a git checkout (just as expected) but also after a git clone (unless you pass --no-checkout). Very well, now, considering the following: you don't have a local repository before a git…
Geoffrey Bachelet
  • 4,047
  • 2
  • 21
  • 17
39
votes
4 answers

Anonymous functions in WordPress hooks

WordPress hooks can be used in two ways: using callback function name and appropriate function add_action( 'action_name', 'callback_function_name' ); function callback_function_name() { // do something } using anonymous function…
Aleksandr Levashov
  • 403
  • 1
  • 4
  • 7