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
2
votes
3 answers

Git Server Hooks - Are they executed locally on the client/clone machine?

Setup: I have master repo on Windows machine and a clone on another windows machine. Inside my update hook, I have added ipconfig to print IP address. I was expecting to see the master's IP address, but it actually prints out clone's. This makes me…
2
votes
2 answers

wordpress: how do actions get executed?

Do custom hooks that hook onto wordpress core get executed automatically by wordpress or do we have to call the do_action function on the custom made hook…
dave
  • 14,991
  • 26
  • 76
  • 110
2
votes
1 answer

gcc / Linux : hook exit() call to prevent exit from happening

I have a pretty unique case where I am calling a 3rd party library (which I cannot modify) from a higher-level C program. This code has a clean-up routine that calls exit() - which terminates the whole application. However, I do not want to…
John McGrath
  • 151
  • 1
  • 11
2
votes
1 answer

Powershell returns nothing in TortoiseGit hook

I am developing simple hook for git. It should cancel commit / push if Acrobat is opened on Windows Machine. Since Git hooks can not find windows process directly i am running next Powershell script named pre-commit.ps1 UPD No solution so far.…
Lev Savranskiy
  • 422
  • 2
  • 7
  • 19
2
votes
2 answers

Get text from a button in an application using win32 C++ and hooks

I am trying to retrieve the text of a button on Calculator (calc.exe) using Winapi. I have hooked WH_CALLWNDPROC and the hook works fine. But I am unable to retrieve the text of any button (say numeric 7). I am using GetDlgItemText: TCHAR…
stamhaney
  • 1,246
  • 9
  • 18
2
votes
1 answer

TortoiseGit hook scripts can not prevent start-commit

I using msysgit and TortoiseGit 1.8.15.0 under Windows 7, and then set my start-commit-hook scripts file to './workflow.bat'. the script file content as follows: echo --------------------------------------------------------------------------- 1>&2 …
2
votes
1 answer

C# Keyboard hook throws System.NullReferenceException

When discussing keyboard hooking, this article gets thrown around a lot. So I tied the class that it suggested: using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using…
Andy
  • 51
  • 4
2
votes
0 answers

C# how to get the IP address from the sockaddr

I hook the connect function using deviare , and C#. the issue is I need to get the IP Address from the sockaddr(which is the second param in the connect function) . I checked the answers: C# sockaddr to sockaddr_in …
2
votes
1 answer

TortoiseHg error running HG

I'm running into an error when pushing a local repository to the master repository located on a network share in Windows 7. I've added a hook on the master repository to perform "hg update" on push. When I'm running push from the local repository in…
Lav
  • 21
  • 2
2
votes
1 answer

Genesis: Add nav into custom header function

I am trying to make a custom header function in a Genesis child theme that includes site title, description, nav, and one additional div. The nav does not show up with this code: remove_action( 'genesis_after_header', 'genesis_do_nav'…
user2521295
  • 823
  • 2
  • 12
  • 23
2
votes
2 answers

jQuery set CSS color as HEX instead of RGB

I am trying to create a jQuery hook which will read and set all colors as hex values instead of RGB. I have found a hook that will properly read the color as HEX but I am not sure on how to modify it to write CSS colors as HEX. So for example I…
Kupe
  • 665
  • 7
  • 13
2
votes
1 answer

Win32 -- how to manage my mouse hook thread

I have successfully gotten my low-level mouse hook code to work, but there are some behaviors I'm observing that I don't quite understand. Everything works fine if I spawn a thread which installs the mouse hook. When i no longer need it running, I…
Steven Lu
  • 41,389
  • 58
  • 210
  • 364
2
votes
0 answers

woocommerce add action after user registered

Does someone know a hook to add an action after user registered on woocommerce or wordpress? My aim is to add a short code of javascript on site header after user is registered on my woocommerce site, something like this : add_action(…
user3137766
2
votes
1 answer

add a filter to add a class to tag link in wordpress

I want to add a filter to revise the link generated by get_the_tag_list in WP. It calls up get_the_term_list function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '' ) { $terms = get_the_terms( $id, $taxonomy ); if (…
antonanton
  • 581
  • 4
  • 13
  • 30
2
votes
1 answer

Set keyboard hook to TextBox

Every windows hook is set to a particular window, or is global. And if I'm not wrong, even the textbox is a window. So, is it possible to set a low level keyboard hook to a specific textbox? My goal is to capture keydown event on my textbox, but I…
Kolan
  • 103
  • 1
  • 5